list of attached databases

How can I, programatically, get a list of attached databases I'm using VB.

Answer this question

list of attached databases

  • DirectShow

    You can create Connection objects independently of any other previously defined object.

    You can execute commands or stored procedures as if they were native methods on the Connection object.

    To execute a command, give the command a name using the Command object Name property. Set the Command object's ActiveConnection property to the connection. Then issue a statement where the command name is used as if it were a method on the Connection object, followed by any parameters, then followed by a Recordset object if any rows are returned. Set the Recordset properties to customize the resulting Recordset. For example:

    Dim cnn As New ADODB.Connection
    Dim cmd As New ADODB.Command
    Dim rst As New ADODB.Recordset
    ...
    cnn.Open "..."
    cmd.Name = "yourCommandName"
    cmd.ActiveConnection = cnn
    ...
    'Your command name, any parameters, and an optional Recordset.
    cnn.yourCommandName "parameter", rst

    To execute a stored procedure, issue a statement where the stored procedure name is used as if it were a method on the Connection object, followed by any parameters. ADO will make a "best guess" of parameter types. For example:

    Dim cnn As New ADODB.Connection
    ...
    'Your stored procedure name and any parameters.
    cnn.sp_yourStoredProcedureName "parameter"
     
    Hope, it helps.


  • jd_scribe

    You can execute

    select name from sys.databases from the client application.

    Hope, it helps.



  • dioptre

    Thank you Zoya; that answers most of what I want to know. Now a follow-up question:

    I can run the query in SMS; but how would I do that from a vb app Without a db name, what kind of connection would I have to make to execute sql statement


  • list of attached databases