Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Listing Database Names

Listing Database Names

Scheduled Pinned Locked Moved C#
databasesql-serversysadminquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 2056922
    wrote on last edited by
    #1

    How can I list all the databases that are available with sql server 2000.

    M 1 Reply Last reply
    0
    • U User 2056922

      How can I list all the databases that are available with sql server 2000.

      M Offline
      M Offline
      Mohamad Al Husseiny
      wrote on last edited by
      #2

      SqlServer have sp_databases Stored Procedure which list databases available in the server instance you can write somthing like

      private 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

      U 1 Reply Last reply
      0
      • M Mohamad Al Husseiny

        SqlServer have sp_databases Stored Procedure which list databases available in the server instance you can write somthing like

        private 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

        U Offline
        U Offline
        User 2056922
        wrote on last edited by
        #3

        Fantastic!! I will give this a go and see how it works! Much Appreciated.:-D

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups