5/05/2011

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)
       ddlDatabases.Items.Add(db.Name);

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


2 comments:

Post a Comment

Twitter Delicious Facebook Digg Favorites More