private bool AttemptToCreateDatabase()
        {
            var prop = ConnectionProperties as MySqlConnectionProperties;

            if (prop == null)
            {
                return(false);
            }

            var    cb    = prop.ConnectionStringBuilder;
            string olddb = (string)cb["Database"];

            cb["Database"] = "";
            try
            {
                using (var 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 ex)
            {
                MySqlSourceTrace.WriteAppErrorToLog(ex, null, string.Format(Resources.ErrorAttemptingToCreateDB, dbList.Text), true);
                return(false);
            }
            finally
            {
                cb["Database"] = olddb;
            }
        }
        private bool DatabaseExists()
        {
            var prop = ConnectionProperties as MySqlConnectionProperties;

            if (prop == null)
            {
                return(false);
            }

            var cb = prop.ConnectionStringBuilder;

            try
            {
                using (var 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.ToLower().Contains("unknown database"))
                {
                    return(false);
                }

                throw;
            }
        }
        private void dbList_DropDown(object sender, EventArgs e)
        {
            if (_dbListPopulated)
            {
                return;
            }

            var prop = ConnectionProperties as MySqlConnectionProperties;

            if (prop == null)
            {
                return;
            }

            var cb = prop.ConnectionStringBuilder;

            try
            {
                using (var conn = new MySqlConnectionSupport())
                {
                    conn.Initialize(null);
                    conn.ConnectionString = cb.ConnectionString;
                    conn.Open(false);
                    dbList.Items.Clear();
                    using (var 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 ex)
            {
                MySqlSourceTrace.WriteAppErrorToLog(ex, Resources.ErrorTitle, Resources.UnableToRetrieveDatabaseList, true);
            }
        }
        /// <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 = ConnectionStringBuilder.ConnectionString;
                // Try to open
                conn.Open(false);
                // Close after open
                conn.Close();
            }
            finally
            {
                // In any case dispose connection support
                conn.Dispose();
            }
        }