Hey all, I have a pretty simple question, how do i get a list of all databases on a given SQL server
I just want a list of them, how is this done I know that you can use SMO, but I am acutally trying to do this without using SMO. Can it be done
Thanks to anyone who helps

Get list of all Databases in an SQL server
yeukwong999
shreeman
ltan68219
pbergeron
SqlConnection sqlConn = new SqlConnection("Server=theServer; Database=dbName; User Id=user; password=password");
sqlConn.Open();
DataTable tblDatabases = sqlConn.GetSchema("Databases");
sqlConn.Close();
foreach (DataRow row in tblDatabases.Rows)
{
databasesList.Items.Add(row["database_name"]);
}
Seemed to work just fine.
Thanks to all who helped me so far
Don Griest
Hi, there are many options, some of them are listed below:
--SQL2k5
Select
name from sys.sysdatabases--Pre SQL2k5
Select
name from dbo.sysdatabases--System procedure
sp_helpdb
HTH, jens Suessmeyer.
Grigori Somin
Hi,
You could use GetOledbSchemaTable method of the OledbConnection class. It allows to get schema information about objects in a database. Remember that you will need appropriate permissions on a server to query this data. Check next link with the sample
http://support.microsoft.com/kb/309488/en-us