private async Task TestConnection() { progressSpinnerDefault.Visible = true; IDatabaseInterface sqlInterface = DatabaseInterfaceFactory.Factory(comboBoxProvider.SelectedItem.ToString()); if (checkBoxWindowsAuth.Checked) { this.ConnectionString = sqlInterface.CreateConnectionStringUsingWindowsAuthentication(textBoxInstance.Text, comboBoxDatabases.SelectedValue?.ToString()); } else { this.ConnectionString = sqlInterface.CreateConnectionString(textBoxInstance.Text, comboBoxDatabases.SelectedValue?.ToString(), textBoxUsername.Text, textBoxPassword.Text); } sqlInterface.SetConnectionString(this.ConnectionString); if (await sqlInterface.TestConnectionAsync()) { this.SetUserMessage("Connected!", false); await LoadDatabases(); } else { this.SetUserMessage("Unable to Connect...", true); } progressSpinnerDefault.Visible = false; }
private void buttonSave_Click(object sender, EventArgs e) { if (comboBoxDatabases.SelectedIndex > -1) { this.Saved = true; this.Provider = comboBoxProvider.Text; IDatabaseInterface sqlInterface = DatabaseInterfaceFactory.Factory(comboBoxProvider.SelectedItem.ToString()); if (this.checkBoxWindowsAuth.Checked) { this.ConnectionString = sqlInterface.CreateConnectionStringUsingWindowsAuthentication(textBoxInstance.Text, comboBoxDatabases.SelectedValue?.ToString()); } else { this.ConnectionString = sqlInterface.CreateConnectionString(textBoxInstance.Text, comboBoxDatabases.SelectedValue?.ToString(), textBoxUsername.Text, textBoxPassword.Text); } ConfigHelper.WriteAppSetting("DatabaseInstance", textBoxInstance.Text); ConfigHelper.WriteAppSetting("DatabaseUsername", textBoxUsername.Text); ConfigHelper.WriteAppSetting("DatabaseProvider", comboBoxProvider.SelectedItem?.ToString()); this.Close(); } else { SetUserMessage("Database not selected...", true); } }
private async Task LoadDatabases() { try { IDatabaseInterface sqlInterface = DatabaseInterfaceFactory.Factory(comboBoxProvider.SelectedItem.ToString()); if (this.checkBoxWindowsAuth.Checked) { this.ConnectionString = sqlInterface.CreateConnectionStringUsingWindowsAuthentication(textBoxInstance.Text, comboBoxDatabases.SelectedValue?.ToString()); } else { this.ConnectionString = sqlInterface.CreateConnectionString(textBoxInstance.Text, comboBoxDatabases.SelectedValue?.ToString(), textBoxUsername.Text, textBoxPassword.Text); } progressSpinnerDefault.Visible = true; comboBoxDatabases.DataSource = null; resetUserMessage(); sqlInterface.SetConnectionString(this.ConnectionString); bool result = sqlInterface.TestConnection(); if (result) { SetUserMessage("Connected!", false); comboBoxDatabases.DataSource = await Task <List <string> > .Run(() => { List <string> databases = sqlInterface.GetDatabaseList(); databases.Sort(); return(databases); }); } else { SetUserMessage("Unable to Connect...", true); } } catch (Exception ex) { SetUserMessage($"Unable to Connect...Error={ex.Message}", true); } finally { progressSpinnerDefault.Visible = false; } }