SolutionCottage.com
Posted  08 Apr 2009 - 15:29:26

Category: ASP.net


How to get a list of all databases on a server

Issue:
You want to have a list of the databases on your server, maybe for selecting them using a dropdown.

Solution:
Use something like this:

SqlConnection conn = new SqlConnection(connectionString);
conn.Open();
SqlCommand comm = new SqlCommand();
comm.Connection = conn;
comm.CommandType = CommandType.StoredProcedure;
comm.CommandText = "sp_databases";

SqlDataReader reader = comm.ExecuteReader();

while (reader.Read())
{
cmbDatabases.Items.Add(reader.GetString(0));
}
conn.Close();








0 comments:








© SolutionCottage 2008-2011 9/26/2017 10:10:45 AM