Open() public method

public Open ( bool doPromptCheck ) : bool
doPromptCheck bool
return bool
Exemplo n.º 1
0
        private bool AttemptToCreateDatabase()
        {
            AdoDotNetConnectionProperties prop =
                (ConnectionProperties as AdoDotNetConnectionProperties);
            DbConnectionStringBuilder cb = prop.ConnectionStringBuilder;

            string olddb = (string)cb["Database"];

            cb["Database"] = "";
            try
            {
                using (MySqlConnectionSupport conn = new MySqlConnectionSupport())
                {
                    conn.Initialize(null);
                    conn.ConnectionString = cb.ConnectionString;
                    conn.Open(false);
                    conn.ExecuteWithoutResults("CREATE DATABASE `" + dbList.Text + "`", 1, null, 0);
                }
                return(true);
            }
            catch (Exception)
            {
                MessageBox.Show(String.Format(Resources.ErrorAttemptingToCreateDB, dbList.Text));
                return(false);
            }
            finally
            {
                cb["Database"] = olddb;
            }
        }
Exemplo n.º 2
0
        private bool DatabaseExists()
        {
            AdoDotNetConnectionProperties prop =
                (ConnectionProperties as AdoDotNetConnectionProperties);
            DbConnectionStringBuilder cb = prop.ConnectionStringBuilder;

            try
            {
                using (MySqlConnectionSupport conn = new MySqlConnectionSupport())
                {
                    conn.Initialize(null);
                    conn.ConnectionString = cb.ConnectionString;
                    conn.Open(false);
                }
                return(true);
            }
            catch (DbException ex)
            {
                string msg = ex.Message.ToLowerInvariant();
                if (msg.StartsWith("unknown database"))
                {
                    return(false);
                }
                throw;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Test connection for these properties. Uses MySqlConnection support for version validation.
        /// </summary>
        public override void Test()
        {
            // Create connection support
            MySqlConnectionSupport conn = new MySqlConnectionSupport();

            try
            {
                // Initializes it with empty provider
                conn.Initialize(null);
                // Set connection string
                conn.ConnectionString = ToTestString();
                // Try to open
                conn.Open(false);
                // Close after open
                conn.Close();
            }
            finally
            {
                // In any case dispose connection support
                if (conn != null)
                {
                    conn.Dispose();
                }
            }
        }
Exemplo n.º 4
0
        private void dbList_DropDown(object sender, EventArgs e)
        {
            if (dbListPopulated)
            {
                return;
            }

            AdoDotNetConnectionProperties prop =
                (ConnectionProperties as AdoDotNetConnectionProperties);
            DbConnectionStringBuilder cb = prop.ConnectionStringBuilder;

            try
            {
                using (MySqlConnectionSupport conn = new MySqlConnectionSupport())
                {
                    conn.Initialize(null);
                    conn.ConnectionString = cb.ConnectionString;
                    conn.Open(false);
                    dbList.Items.Clear();
                    using (DataReader reader = conn.Execute("SHOW DATABASES", 1, null, 0))
                    {
                        while (reader.Read())
                        {
                            string dbName = reader.GetItem(0).ToString().ToLowerInvariant();
                            if (dbName == "information_schema")
                            {
                                continue;
                            }
                            if (dbName == "mysql")
                            {
                                continue;
                            }
                            dbList.Items.Add(reader.GetItem(0));
                        }
                        dbListPopulated = true;
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show(Resources.UnableToRetrieveDatabaseList);
            }
        }
 /// <summary>
 /// Test connection for these properties. Uses MySqlConnection support for version validation.
 /// </summary>
 public override void Test()
 {
     // Create connection support
     MySqlConnectionSupport conn = new MySqlConnectionSupport();
     try
     {
         // Initializes it with empty provider
         conn.Initialize(null);
         // Set connection string
         conn.ConnectionString = ToTestString();
         // Try to open
         conn.Open(false);
         // Close after open
         conn.Close();
     }
     finally
     {
         // In any case dispose connection support
         if (conn != null)
             conn.Dispose();
     }
 }
        private bool AttemptToCreateDatabase()
        {
            AdoDotNetConnectionProperties prop =
                (ConnectionProperties as AdoDotNetConnectionProperties);
            DbConnectionStringBuilder cb = prop.ConnectionStringBuilder;

            string olddb = (string)cb["Database"];
            cb["Database"] = "";
            try
            {
                using (MySqlConnectionSupport conn = new MySqlConnectionSupport())
                {
                    conn.Initialize(null);
                    conn.ConnectionString = cb.ConnectionString;
                    conn.Open(false);
                    conn.ExecuteWithoutResults("CREATE DATABASE `" + dbList.Text + "`", 1, null, 0);
                }
                return true;
            }
            catch (Exception)
            {
                MessageBox.Show(String.Format(Resources.ErrorAttemptingToCreateDB, dbList.Text));
                return false;
            }
            finally
            {
                cb["Database"] = olddb;
            }
        }
        private bool DatabaseExists()
        {
            AdoDotNetConnectionProperties prop =
                (ConnectionProperties as AdoDotNetConnectionProperties);
            DbConnectionStringBuilder cb = prop.ConnectionStringBuilder;

            try
            {
                using (MySqlConnectionSupport conn = new MySqlConnectionSupport())
                {
                    conn.Initialize(null);
                    conn.ConnectionString = cb.ConnectionString;
                    conn.Open(false);
                }
                return true;
            }
            catch (DbException ex)
            {
                string msg = ex.Message.ToLowerInvariant();
                if (msg.StartsWith("unknown database")) return false;
                throw;
            }
        }
        private void dbList_DropDown(object sender, EventArgs e)
        {
            if (dbListPopulated) return;

            AdoDotNetConnectionProperties prop =
                (ConnectionProperties as AdoDotNetConnectionProperties);
            DbConnectionStringBuilder cb = prop.ConnectionStringBuilder;

            try
            {
                using (MySqlConnectionSupport conn = new MySqlConnectionSupport())
                {
                    conn.Initialize(null);
                    conn.ConnectionString = cb.ConnectionString;
                    conn.Open(false);
                    dbList.Items.Clear();
                    using (DataReader reader = conn.Execute("SHOW DATABASES", 1, null, 0))
                    {
                        while (reader.Read())
                        {
                            string dbName = reader.GetItem(0).ToString().ToLowerInvariant();
                            if (dbName == "information_schema") continue;
                            if (dbName == "mysql") continue;
                            dbList.Items.Add(reader.GetItem(0));
                        }
                        dbListPopulated = true;
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show(Resources.UnableToRetrieveDatabaseList);
            }
        }