Pages

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:

Unknown said...

Great Code snippet,,,
Follow me and i will list ur site on my Blog,,,
thanks
http://techterabyte.blogspot.in/

darichkid said...

Here is a database compatible with .NET, Silverlight, Windows Phone, Mono, Monodroid, and Monotouch:
http://www.kellermansoftware.com/p-43-ninja-net-database-pro.aspx

Post a Comment

Twitter Delicious Facebook Digg Favorites More