You can use SqlConnection.GetSchema:
using(var con = new SqlConnection("Data Source=Yourserver; Integrated Security=True;"))
{
con.Open();
DataTable databases = con.GetSchema("Databases");
foreach (DataRow database in databases.Rows)
{
String databaseName = database.Field("database_name");
short dbID = database.Field("dbid");
DateTime creationDate = database.Field("create_date");
}
}
SQL Server Schema Collections (ADO.NET)
To determine the list of supported schema collections, call the
GetSchema method with no arguments, or with the schema collection name
"MetaDataCollections". This will return a DataTable with a list of the
supported schema collections, the number of restrictions that they
each support, and the number of identifier parts that they use.