Results 1 to 10 of 10

Thread: VB 6.0:Get the list of all SQL Servers in the Network

  1. #1

    Thread Starter
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    VB 6.0:Get the list of all SQL Servers in the Network

    Sometimes we need a list of all the SQL Servers present on the network. There are lot of code snippets on the internet to do just that, however I did not find anything in the VBF Codebank.

    So here is a function that will return an array f all the SQL Servers present in the network. In order to run this function you will have to set reference to Microsoft SQLDMO Object Library (Goto Projects-->References and select Microsoft SQLDMO Object Library)
    VB Code:
    1. 'Function : listSQLServers
    2. 'Input Parameter : None
    3. 'Return Value:  Returns an Array that consists of the
    4. '               names of the SQLServers available
    5. Public Function listSQLServers() As String()
    6.    
    7.     'set reference to Microsoft SQLDMO Object Library
    8.     'prior to using this code
    9.     Dim sqlApp As New SQLDMO.Application
    10.     Dim serverNameList As SQLDMO.NameList
    11.     'an empty array that will hold all the servernames
    12.     Dim serverNames() As String
    13.     Dim loopCounter As Long
    14.            
    15.     'get all the SQL Servers available
    16.     Set serverNameList = sqlApp.ListAvailableSQLServers
    17.     'if no servers exist then return to the calling function
    18.     If serverNameList.Count = 0 Then
    19.         Set sqlApp = Nothing
    20.         Set serverNameList = Nothing
    21.         Exit Function
    22.     End If
    23.     'Redim the array with the proper count
    24.     ReDim serverNames(serverNameList.Count)
    25.        
    26.     'loop through all the servers
    27.     For loopCounter = 0 To serverNameList.Count
    28.         'add to the array
    29.         serverNames(loopCounter) = serverNameList.Item(loopCounter)
    30.     Next
    31.        
    32.     listSQLServers = serverNames
    33.        
    34.     'release objects
    35.     Set sqlApp = Nothing
    36.     Set serverNameList = Nothing
    37.     Exit Function
    38.  
    39. End Function
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  2. #2
    New Member
    Join Date
    May 2006
    Posts
    10

    Re: VB 6.0:Get the list of all SQL Servers in the Network

    This is not working for me. Its not even returning my (local) server (SQl Server and SQl Server Agent are both started and running)

    Hwoever, I can find the server buried way down in servernameList.Application.ServerGroups.Item(1).RegisteredServers.Item(1).Name even though the serverNameList.Count = 0.

    Any thoughts?

    Using VB6, SQL2000, XP Pro SP2

  3. #3

    Thread Starter
    Shared Member
    Join Date
    May 2005
    Location
    Kashmir, India
    Posts
    2,277

    Re: VB 6.0:Get the list of all SQL Servers in the Network

    Works perfectly for me.

    If serverNameList.Count = 0 then that means there are no servers in your network.
    Use [code] source code here[/code] tags when you post source code.

    My Articles

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB 6.0:Get the list of all SQL Servers in the Network

    Yes, I have coded this way for years and its always worked.

    http://vbforums.com/showpost.php?p=1437973&postcount=6
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    New Member
    Join Date
    May 2006
    Posts
    10

    Re: VB 6.0:Get the list of all SQL Servers in the Network

    For some reason its not working on my machine. I the only SQL Server on the network right now and it is running. I can see and connect through ADO, but not DMO. I have the DMO Object Lib and SQLNamespace references added and moved above ADO actually.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB 6.0:Get the list of all SQL Servers in the Network

    Your SQL is running on an XP SP-2 system or an actual server?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7
    New Member
    Join Date
    May 2006
    Posts
    10

    Re: VB 6.0:Get the list of all SQL Servers in the Network

    its running on the XP SP2 system. Here at work we run all local installs but allow connections from other users on other machines to access data. I can see my machine and others in the ODBC tool, using the ADO login prompt, etc.

    is there another setup I should be using to list available 'servers'?

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB 6.0:Get the list of all SQL Servers in the Network

    So your not running a Domain?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9
    New Member
    Join Date
    May 2006
    Posts
    10

    Re: VB 6.0:Get the list of all SQL Servers in the Network

    the office is running on a domain, but i am remote 99% of the time. i log into my laptop using a domain account, but unless I VPN into the office, I am using cached credientials (though I need to log in to the machine before I can even launch VPN)

    the SQL installs we have accept either windows authentication or a SQL user/pass

    I am not running a domain controller on this machine if that is what you are asking.

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB 6.0:Get the list of all SQL Servers in the Network

    so if your system is running sql on it and you vpn in to your companies domain then your local sql may not return as its not officially "on" the network. Its more of a secure mapped drive.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

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



Click Here to Expand Forum to Full Width