How can I list all the instances available in a server machine (1 Viewer)

accesser2003

Registered User.
Local time
Today, 03:27
Joined
Jun 2, 2007
Messages
124
If my computer name is Elephant, and I want to look for all the SQL instances at this computer, How can I get those?
 

KenHigg

Registered User
Local time
Yesterday, 20:27
Joined
Jun 9, 2004
Messages
13,327
(There must be an appropriate elephant joke for this but I just can't think of one at the moment - :) )
 
Local time
Yesterday, 19:27
Joined
Mar 4, 2008
Messages
3,856
Through Enterprise Manager.
 

DCrake

Remembered
Local time
Today, 01:27
Joined
Jun 8, 2005
Messages
8,626
Simple Software Solutions

Here is a samll function that searches for all available servers connected to the host pc


You will need to add Microsoft SQLDMO Object Library to your references first.

Code:
Public Function ListConnectedSQLServers()
    Dim i As Integer
    Dim oNames As SQLDMO.NameList
    Dim oSQLApp As SQLDMO.Application
    Set oSQLApp = New SQLDMO.Application
    
    Set oNames = oSQLApp.ListAvailableSQLServers()
    SysServerCount = oNames.Count
    If SysServerCount = 0 Then
        ArrayServers(0) = "LOCAL"
    Else
        For i = 0 To SysServerCount - 1
            ArrayServers(i) = oNames.Item(i)
        Next i
    End If
    
End Function

In this sample I declared an array and a interger variable, ArrayServers and SysServerCount respectively.

The code enumerates and passes the SQL server names to the array. Which can be used to populate a list box or combobox later. If the servercound is greater than zero. This is used to warn the user that no SQL servers could be detected.

CodeMaster::cool:
 

Users who are viewing this thread

Top Bottom