Exemple #1
0
        private void SqlServerOKBtn_Click(object sender, RoutedEventArgs e)
        {
            bool          windowsAuth = WindowsAuthenticationRadioBtn.IsChecked ?? true;
            SqlConnection connection  = DBUtils.CreateSqlServerConnection(
                server: SqlServerHostTextBox.Text,
                username: SqlServerUsernameTextBox.Text,
                password: SqlServerPasswordTextBox.Password,
                useWindowsAuthentication: windowsAuth,
                noDB: true);

            try
            {
                connection.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection failed with error: " + ex.Message);
                return;
            }

            if (WindowsAuthenticationRadioBtn.IsChecked != null)
            {
                Properties.Settings.Default.sqlServerUseWindowsAuthentication = WindowsAuthenticationRadioBtn.IsChecked.Value;
            }
            Properties.Settings.Default.sqlServerHost     = SqlServerHostTextBox.Text;
            Properties.Settings.Default.sqlServerUsername = SqlServerUsernameTextBox.Text;
            Properties.Settings.Default.sqlServerPassword = EncryptionUtils.Protect(SqlServerPasswordTextBox.Password);
            Properties.Settings.Default.databaseType      = "SqlServer";

            Properties.Settings.Default.Save();

            Close();
        }
Exemple #2
0
        private static void InitializeSqlServerDb()
        {
            using (var conn = DBUtils.CreateSqlServerConnection("",
                                                                Settings.Default.sqlServerHost,
                                                                Settings.Default.sqlServerUsername,
                                                                EncryptionUtils.Unprotect(Settings.Default.sqlServerPassword),
                                                                useWindowsAuthentication: Settings.Default.sqlServerUseWindowsAuthentication,
                                                                noDB: true))
            {
                conn.Open();
                using (var cmd = new SqlCommand("", conn))
                {
                    cmd.CommandText = @"SELECT database_id FROM sys.databases WHERE Name = 'qdmsQuartz'";
                    object id = cmd.ExecuteScalar();
                    if (id == null)
                    {
                        //db does not exist, create it
                        var commands = new List <string>();
                        commands.Add("CREATE DATABASE qdmsQuartz");
                        commands.Add("USE qdmsQuartz");
                        Regex regex = new Regex(@"\r{0,1}\nGO\r{0,1}\n");
                        commands.AddRange(regex.Split(Resources.QuartzSqlServerDbInit)); //needed because all the 'GO' things in the script;

                        foreach (string command in commands)
                        {
                            cmd.CommandText = command;
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
            }
        }
Exemple #3
0
        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();
            }
        }
Exemple #4
0
        private void SqlServerTestConnectionBtn_Click(object sender, RoutedEventArgs e)
        {
            bool windowsAuth = WindowsAuthenticationRadioBtn.IsChecked ?? true;

            SqlConnection connection = DBUtils.CreateSqlServerConnection(
                server: SqlServerHostTextBox.Text,
                username: SqlServerUsernameTextBox.Text,
                password: SqlServerPasswordTextBox.Password,
                useWindowsAuthentication: windowsAuth,
                noDB: true);

            try
            {
                connection.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Connection failed with error: " + ex.Message);
                return;
            }

            MessageBox.Show("Connection succeeded.");
            connection.Close();
        }