Getting all databases from Sql Server 2005-2008 using c#

This code will help you in getting all databases of Sql Server and show them in the drop down list.

SqlConnection connection = new SqlConnection(connectionstring);

ServerConnection conn = new ServerConnection(connection);
Server myServer = new Server(conn);
foreach (Database db in myServer.Databases)

Note: 'ddlDatabases' is the name of combobox. And db.Name contains the name of the database

Twitter Delicious Facebook Digg Favorites More