private void MySqlOKBtn_Click(object sender, RoutedEventArgs e) { MySqlConnection connection = DBUtils.CreateMySqlConnection( server: MySqlHostTextBox.Text, username: MySqlUsernameTextBox.Text, password: MySqlPasswordTextBox.Password, noDB: true); try { connection.Open(); } catch (Exception ex) { MessageBox.Show("Connection failed with error: " + ex.Message); return; } connection.Close(); Properties.Settings.Default.mySqlHost = MySqlHostTextBox.Text; Properties.Settings.Default.mySqlUsername = MySqlUsernameTextBox.Text; Properties.Settings.Default.mySqlPassword = EncryptionUtils.Protect(MySqlPasswordTextBox.Password); Properties.Settings.Default.databaseType = "MySql"; Properties.Settings.Default.Save(); Close(); }
private void MySqlTestConnectionBtn_Click(object sender, RoutedEventArgs e) { MySqlConnection connection = DBUtils.CreateMySqlConnection( server: MySqlHostTextBox.Text, username: MySqlUsernameTextBox.Text, password: MySqlPasswordTextBox.Password, noDB: true); try { connection.Open(); } catch (Exception ex) { MessageBox.Show("Connection failed with error: " + ex.Message); return; } MessageBox.Show("Connection succeeded."); connection.Close(); }
private void CheckDBConnection() { //if no db type has been selected, we gotta show that window no matter what if (Properties.Settings.Default.databaseType != "MySql" && Properties.Settings.Default.databaseType != "SqlServer") { var dbDetailsWindow = new DBConnectionWindow(); dbDetailsWindow.ShowDialog(); } if (Properties.Settings.Default.databaseType == "MySql") { //try to establish a database connection. If not possible, prompt the user to enter details var connection = DBUtils.CreateMySqlConnection(noDB: true); try { connection.Open(); } catch (Exception) { var dbDetailsWindow = new DBConnectionWindow(); dbDetailsWindow.ShowDialog(); } connection.Close(); } else //SQL Server { //try to establish a database connection. If not possible, prompt the user to enter details var connection = DBUtils.CreateSqlServerConnection(noDB: true, useWindowsAuthentication: Properties.Settings.Default.sqlServerUseWindowsAuthentication); try { connection.Open(); } catch (Exception) { var dbDetailsWindow = new DBConnectionWindow(); dbDetailsWindow.ShowDialog(); } connection.Close(); } }
private static void InitializeMySqlDb() { using (var conn = DBUtils.CreateMySqlConnection(noDB: true)) { conn.Open(); using (var cmd = new MySqlCommand("", conn)) { cmd.CommandText = "SHOW DATABASES LIKE 'qdmsQuartz'"; var reader = cmd.ExecuteReader(); if (!reader.Read()) { //db does not exist, create it reader.Close(); cmd.CommandText = @"CREATE DATABASE qdmsQuartz; USE qdmsQuartz;" + Resources.QuartzMySqlDbInit; cmd.ExecuteNonQuery(); } } } }