retrieve list of databases from .net

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
 
J

j-in-uk

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top