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.