private void LoadDB() { try { using (MySqlConnection sqlConnection = ConnectionClass.GetStringConnectionSettings(txtServer.Text, txtLogin.Text, txtPass.Text)) { if (sqlConnection.State == ConnectionState.Closed) { sqlConnection.Open(); } MySqlCommand sqlCommand = new MySqlCommand("SHOW DATABASES", sqlConnection); MySqlDataReader reader = sqlCommand.ExecuteReader(); dbName.Clear(); while (reader.Read()) { dbName.Add(reader.GetString(0)); } cbDB.DataSource = null; cbDB.DataSource = dbName; } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); logger.Debug("\n/--------------------------------------------------------------------/\n" + ex.StackTrace + "\n//----------------------------//\n" + ex.Message + "\n\n"); } }
private void BtnCheckConnect_Click(object sender, EventArgs e) { try { using (MySqlConnection sqlConnection = ConnectionClass.GetStringConnectionSettings(txtServer.Text, txtLogin.Text, txtPass.Text)) { sqlConnection.Open(); if (sqlConnection.State == ConnectionState.Open) { MessageBox.Show("Соединение успешно установлено", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Проверьте правильность введенных данных", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Warning); } sqlConnection.Close(); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); logger.Debug("\n/--------------------------------------------------------------------/\n" + ex.StackTrace + "\n//----------------------------//\n" + ex.Message + "\n\n"); } }