private void GetSQLDetails(ListBox SQLListBox) { SQLInfoEnumerator sie = new SQLInfoEnumerator(); try { if (SQLListBox.Name == "listboxSQLServerDatabaseInstances") { SQLListBox.Items.Clear(); sie.SQLServer = listboxSQLServerInstances.SelectedItem.ToString(); sie.Username = textboxUserName.Text; sie.Password = textboxPassword.Text; SQLListBox.Items.AddRange(sie.EnumerateSQLServersDatabases()); } else { SQLListBox.Items.Clear(); SQLListBox.Items.AddRange(sie.EnumerateSQLServers()); } } catch (Exception ex) { MessageBox.Show(ex.ToString()); } }
public List<SqlDatabaseSettings> GetSQLDatabasesSettings(string pDatabaseServerName, string pDatabaseLoginName, string pDatabasePassword) { SqlConnection connection = ConnectionManager.GeneralSqlConnection; try { connection.Open(); SQLInfoEnumerator sie = new SQLInfoEnumerator { SQLServer = pDatabaseServerName, Username = pDatabaseLoginName, Password = pDatabasePassword }; List<SqlDatabaseSettings> list = new List<SqlDatabaseSettings>(); foreach (string database in sie.EnumerateSQLServersDatabases()) { SqlDatabaseSettings sqlDatabase = _GetDatabaseInfos(database, connection); if (sqlDatabase == null) continue; list.Add(sqlDatabase); } connection.Close(); List<string> filter = TechnicalSettings.AvailableDatabases; return list.FindAll(db => 0 == filter.Count || filter.Contains(db.Name)); } catch (Exception) { connection.Close(); throw; } }