private void PopulateDatabaseNameItemsWorker(object sender, DoWorkEventArgs e) { BackgroundWorker backgroundWorker = sender as BackgroundWorker; if (backgroundWorker == null) { return; } String[] databaseArray = null; try { if (!String.IsNullOrEmpty(this.serverName)) { using (ImpersonationHelper impersonationHelper = new ImpersonationHelper()) { databaseArray = SetupDatabaseHelper.GetSqlDBNames( !SetupDatabaseHelper.SqlServerIsOnLocalComputer(this.serverName), this.serverName, IsDefaultInstance(this.selectedInstance) ? String.Empty : this.selectedInstance, this.port, true); } } } catch (Exception) { } finally { e.Result = databaseArray; } }
private void comboBoxExistingDatabaseName_DropDownOpened(object sender, EventArgs e) { this.DisableInputMode(); this.resetServerName(); this.resetInstanceName(); String[] databaseArray = null; try { if (!String.IsNullOrEmpty(this.serverName)) { using (ImpersonationHelper impersonationHelper = new ImpersonationHelper()) { databaseArray = SetupDatabaseHelper.GetSqlDBNames( !SetupDatabaseHelper.SqlServerIsOnLocalComputer(this.serverName), this.serverName, IsDefaultInstance(this.selectedInstance) ? String.Empty : this.selectedInstance, this.port, true); } } } catch (Exception) { } finally { this.EnableInputMode(); this.comboBoxExistingDatabaseName.Text = String.Empty; this.comboBoxExistingDatabaseName.Items.Clear(); if (databaseArray != null && databaseArray.Length > 0) { foreach (String databaseName in databaseArray) { this.comboBoxExistingDatabaseName.Items.Add(databaseName); } // First satisfy the below scenario: // - User clicked on existing db radio button and selected a db // - then clicked new db radio button // - and then clicked existing radio db again w/o changin server, instance, or port info // Basically, check if the selected instance already exists in the list // if yes, then choose it // otherwise, this is a new population, select the first item if (this.comboBoxExistingDatabaseName.Items.Contains(this.selectedDatabase)) { this.comboBoxExistingDatabaseName.Text = selectedDatabase; } else { this.selectedDatabase = databaseArray[0]; this.comboBoxExistingDatabaseName.Text = this.selectedDatabase; } } } }