retrieve list of databases from .net

  • Thread starter Thread starter j-in-uk
  • Start date Start date
J

j-in-uk

Can i get a list of sql databases by just connecting to the server
programmatically

string myConnString = "Integrated Security=SSPI;Initial
Catalog={0};Data Source=" + serverName +";";
SqlConnection cn = new SqlConnection(myConnString);
cn.Open();
SqlDataReader dr = (new SqlCommand("sp_databases",
cn)).ExecuteReader();
while (dr.Read())
{
lstDatabases.Items.Add(dr["DATABASE_NAME"]);
}

This does not work cos I don't know the name of database/initial
catalog at this point
 
Thanks, master worked. I am using NetServerEnum to get a list of the
sqlServers, I realise that this does not return sqlExpress servers but
get everything else. Do you know what returns SQLExpress & other sql
servers?

thanks
 
Back
Top