title: Get list of database depends on chosen server
body: <p>I'm using C# with framework 4.0 and SQL server 2008 R2.
  I have listed the SQL server 2008 with this code:</p>
  
  <pre><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 &amp;&amp; !string.IsNullOrEmpty(Instance))
                  {
                      SQLServer += "\\" + Instance;
                  }
                  SQLServers[System.Math.Max(System.Threading.Interlocked.Increment(ref f), f - 1)] = SQLServer;
              }
              Array.Sort(SQLServers);
              return SQLServers;
          }
  </code></pre>
  
  <p>i listed my Server on ComboBox.</p>
  
  <p>How can I list the database, depends on which server that I choose in  ComboBox?</p>
  
  <p>I found this <a href="http://4rapiddev.com/csharp/c-get-list-of-databases-in-sql-server/" rel="noreferrer">tutorial</a>, but it needs <code>sqlconnection</code>, how can I connect when I have not chosen the server ?</p>