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(); }
public static bool TestConnection() { if (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) { return(false); } 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: Settings.Default.sqlServerUseWindowsAuthentication); try { connection.Open(); } catch (Exception) { return(false); } connection.Close(); } return(true); }
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 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(); } } } }