How to get all databases name from server

  • I am developing an application in Vb and i have to get all the databases names (catalogs) from the current SQL SERVER 2000 Server . ?

  • Hi msaleem,

    quote:


    I am developing an application in Vb and i have to get all the databases names (catalogs) from the current SQL SERVER 2000 Server . ?


    SELECT name FROM master..sysdatabases WHERE name NOT IN ('master', 'tempdb', 'model', 'msdb')

    returns all user db's.

    Cheers,

    Frank

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • If you're uncomfortable hitting directly against a system table, there is also sp_helpdb with no parameters. However, sp_helpdb will give you more information than it looks like you need.

    K. Brian Kelley

    http://www.truthsolutions.com/

    Author: Start to Finish Guide to SQL Server Performance Monitoring

    http://www.netimpress.com/shop/product.asp?ProductID=NI-SQL1

    K. Brian Kelley
    @kbriankelley

  • Why not use SQL-DMO? With this component you can create SQL Enterprise Manager like applications, with out going for the systemtables. Just add a reference to Microsoft SQLDMO Object Library.

    And this code will do the job:

    Dim oServer As New SQLDMO.SQLServer

    Dim oDatabases As SQLDMO.Databases

    Dim oDB As SQLDMO.Database

    oServer.Connect ServerName, UserName, Password

    Set oDatabases = oServer.Databases

    For Each oDB In oDatabases

    Combobox1.AddItem oDB.Name

    Next

    Look for more details in Books Online.

    Chris

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply