App.Config (Getting the Connection String)
<connectionStrings>
<clear />
<add name="MyConnection" connectionString="Server=ServerName; Database=Any DatabaseName; User Id=Your UserId; Password= Your Password;" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>This will add all the databases to the Combobox,
string connectionString = ConfigurationManager.ConnectionStrings["MyConnection"].ConnectionString.ToString();
using (SqlConnection con = new SqlConnection(connectionString))
{
con.Open();
// Set up a command with the given query and associate
// this with the current connection.
SqlDataAdapter d = new SqlDataAdapter("SELECT name from sys.databases", con);
DataTable dt = new DataTable();
d.Fill(dt);
cmbDatabase.DataSource = dt;
cmbDatabase.DisplayMember = "name";
}