Listing Database Names
C#
3
Posts
2
Posters
0
Views
1
Watching
-
How can I list all the databases that are available with sql server 2000.
-
How can I list all the databases that are available with sql server 2000.
SqlServer have
sp_databases
Stored Procedure which list databases available in the server instance you can write somthing likeprivate void ListDatabases_Click(object sender, System.EventArgs e) { using(SqlConnection cn=new SqlConnection("Server=localhost;Initial Catalog=master;Integrated Security=SSPI;")) { cn.Open(); SqlCommand cmd=new SqlCommand("sp_databases",cn); cmd.CommandType=CommandType.StoredProcedure; SqlDataReader dr=cmd.ExecuteReader(); while(dr.Read()) { Debug.WriteLine(dr.GetString(0)); } dr.Close(); cmd.Dispose(); } }
MCAD -- modified at 21:43 Friday 23rd September, 2005
-
SqlServer have
sp_databases
Stored Procedure which list databases available in the server instance you can write somthing likeprivate void ListDatabases_Click(object sender, System.EventArgs e) { using(SqlConnection cn=new SqlConnection("Server=localhost;Initial Catalog=master;Integrated Security=SSPI;")) { cn.Open(); SqlCommand cmd=new SqlCommand("sp_databases",cn); cmd.CommandType=CommandType.StoredProcedure; SqlDataReader dr=cmd.ExecuteReader(); while(dr.Read()) { Debug.WriteLine(dr.GetString(0)); } dr.Close(); cmd.Dispose(); } }
MCAD -- modified at 21:43 Friday 23rd September, 2005
Fantastic!! I will give this a go and see how it works! Much Appreciated.:-D