Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Location
    Atlanta, GA
    Posts
    58

    Unanswered: Server & Database Name

    Does anyone know how to grab the NT Server name and SQL Database name so it can be displayed on a form?

  2. #2
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346

    Re: Server & Database Name

    You need to reference the SQLDMO Object Library. Here is some sample code:

    Dim appSQL As SQLDMO.Database
    Dim nlServer As NameList
    Dim iCounter As Integer

    Set appSQL = New SQLDMO.Database
    Set nlServer = appSQL.Application.ListAvailableSQLServers

    For iCounter = 1 To nlServer.Count
    MsgBox nlServer.Item(iCounter)
    Next

    Set nlServer = Nothing
    Set appSQL = Nothing
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

  3. #3
    Join Date
    Mar 2004
    Location
    Atlanta, GA
    Posts
    58
    I am a newbie so please excuse me. I used the code above and got the server name but how do I get the database name that I am using?

    Thanks.

  4. #4
    Join Date
    Mar 2004
    Location
    www.scirocco.ca
    Posts
    346
    No problem whatsoever.

    To list all database names it is similar. Here is a list of Servers and Databases

    Dim appSQL As SQLDMO.Database
    Dim nlServer As NameList
    Dim nlDatabase As SQLDMO.Databases
    Dim iCounter As Integer

    On Error GoTo ErrorHandler

    frmSSR016.staMain.Panels("Status").Text = "Loading..."
    Screen.MousePointer = vbHourglass

    txtDatabase = GetRegValue("DatabaseName")
    cboServer.Text = GetRegValue("ServerName")

    Set appSQL = New SQLDMO.Database
    Set nlServer = appSQL.Application.ListAvailableSQLServers

    For iCounter = 1 To nlServer.Count
    MsgBox nlServer.Item(iCounter).Name
    Next

    Set nlDatabase = appSQL.ListObjects(SQLDMOObj_Database)

    For iCounter = 1 To nlDatabase.Count
    MsgBox nlDatabase.Item(iCounter).Name
    Next

    Set nlServer = Nothing
    Set appSQL = Nothing
    http://www.scirocco.ca/images/banner...occobanner.gif

    Download for FREE the ADO/DAO Data Controls that makes life EASIER developing database applications in: VB, FoxPro, Access, VC++, .NET etc... Navigate, Add New, Delete, Update, Search, Undo and Save your changes. Supports Disconnected Recordsets and Transactions!

    Or try our Ask An Expert service to answer any of your questions!

  5. #5
    Join Date
    Mar 2004
    Location
    Atlanta, GA
    Posts
    58
    Sorry for bothering you but I am getting the following error message in the attached file. It is happening on the following line:

    Code:
    Set nlDatabase = appSQL.ListObjects(SQLDMOObj_Database)
    Attached Thumbnails Attached Thumbnails error message.jpg  

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •