private void dialog_ValidatingCreateDatabaseLogin(object sender, ValidatingLoginEventArgs e)
 {
     SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(e.ConnectionInfo.ConnectionString);
     var databaseName = builder.InitialCatalog;
     builder.InitialCatalog = null;
     try
     {
         this.createDatabaseConnection = new SqlConnection(builder.ToString());
         this.createDatabaseConnection.Open();
     }
     catch (Exception ex)
     {
         if (ex is InvalidOperationException || ex is SqlException)
         {
             e.FailMessage = "There was an error connecting to the database. " + ex.Message;
         }
         else
         {
             throw;
         }
     }
 }
 private void dialog_ValidatingLogin(object sender, ValidatingLoginEventArgs e)
 {
     e.FailMessage = InitializeConnection(e.ConnectionInfo);
     if (e.FailMessage == null)
     {
         SettingsFromConnectionInfo(e.ConnectionInfo, Properties.Settings.Default);
         Properties.Settings.Default.Save();
     }
 }
        private string OnValidatingLogin()
        {
            string failMessage = null;
            if (ValidatingLogin != null)
            {
                Cursor.Current = Cursors.WaitCursor;
                var eventArgs = new ValidatingLoginEventArgs { ConnectionInfo = this.connectionInfo };
                ValidatingLogin(this, eventArgs);
                failMessage = eventArgs.FailMessage;
            }

            return failMessage;
        }