I am using C # with framework 4.0 and SQL Server 2008 R2. I have listed SQL Server 2008 using this code:
public static string[] GetSQLServerList() { SqlDataSourceEnumerator dse = SqlDataSourceEnumerator.Instance; DataTable dt = dse.GetDataSources(); if (dt.Rows.Count == 0) { return null; } string[] SQLServers = new string[dt.Rows.Count]; int f = -1; foreach (DataRow r in dt.Rows) { string SQLServer = r["ServerName"].ToString(); string Instance = r["InstanceName"].ToString(); if (Instance != null && !string.IsNullOrEmpty(Instance)) { SQLServer += "\\" + Instance; } SQLServers[System.Math.Max(System.Threading.Interlocked.Increment(ref f), f - 1)] = SQLServer; } Array.Sort(SQLServers); return SQLServers; }
i listed my server in ComboBox.
How can I list the database depends on which server I chose in ComboBox?
I found this tutorial , but it needs sqlconnection , how can I connect when I did not select a server?
source share