Get Registered Server

  • Hello, I got problem when tried to get registered server from IIS on server (installed with IIS and SQL server), but managed to get the registered server when I ran my script with PWS from client PC (installed with PWS and Enterprise Manager). Any idea how to solve this problem?

    thanks ...

    my script:

    
    
    Set objDMOApp = Server.CreateObject("SQLDMO.Application")
    Set objSvrGroups = objDMOApp.ServerGroups
    ReDim tmpServer(0)
    For iIndex = 1 To objSvrGroups.Count
    Set objSvrGroup = objSvrGroups.Item(iIndex)
    Set objRegServers = objSvrGroup.RegisteredServers
    For iIndex2 = 1 To objRegServers.Count
    Set objRegSvr = objRegServers.Item(iIndex2)
    ReDim Preserve tmpServer(UBound(tmpServer, 1) + 1)
    tmpServer(UBound(tmpServer, 1)) = objRegSvr.Name
    Next
    Next
    Set objRegSvr = Nothing
    Set objRegServers = Nothing
    Set objSvrGroup = Nothing
    Set objSvrGroups = Nothing
    Set objDMOApp = Nothing

  • This is my method of doing it.

    Private Sub GetServers()

    Dim NameList As SQLDMO.NameList

    Dim X As Long

    Set NameList = SQL.ListAvailableSQLServers

    For X = 1 To NameList.Count

    cbServers.AddItem NameList.Item(X)

    Next

    End Sub

    cbServers is my ComboBox in VB6

    Hope this helps

    Regards

    Gert

  • sorry before ... can u translate your code to VBScript ... because i cannot get the object for SQLDMO.

     
    
    Set objDMO = Server.CreateObject("SQLDMO.NameList")
    Set NameList = objDMO.ListAvailableSQLServers
    Response.Write "Server Count1: " & NameList.Count & "<br>"
    For X = 1 To NameList.Count
    ReDim Preserve tmpServer(UBound(tmpServer, 1) + 1)
    tmpServer(UBound(tmpServer, 1)) = NameList.Item(X)
    Next
  • I have no experience with VBScript, but I think this is the way to go in VBScript.

    Dim oApp

    Dim oServer

    Dim oDatabase

    Dim oNames

    Dim oName

    Set oApp = CreateObject("SQLDMO.Application")

    Set oNames = oApp.ListAvailableSQLServers()

    For Each oName In oNames

    Set oServer = CreateObject("SQLDMO.SQLServer")

    *** Here you can then put the code on how to display all of the servers***

    Next

    Next

    oApp.Quit

    Set oApp = Nothing

    Hope this helps.

    Regards

    Gert

  • I'd recommend that if you're going to use an array that you dim it once outside the loop. Preserve is a fairly expensive operation if your list is of any great size (though a server list probably wont be!) - still, good to make it efficient as you do it.

    Andy

  • Could be related to your original problem see MS KB Article http://support.microsoft.com/default.aspx?scid=kb;en-us;Q254759 but the last ideas will not work with SQL 7 and ASP.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

  • Hi Antares686, you are right...the last solution cannot work. I am using SQL2000 and ASP. Do you have any idea how to solve this problem?

    Ng Hendry

Viewing 7 posts - 1 through 6 (of 6 total)

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