How to get available SQL Server names?

  • I'm trying to populate a VB6 ComboBox with the names of the available SQL Server servers. How can I do that? I'll appreciate your help.

  • there are number of ways u can find registered servers . one is

    "select * from

    sysservers " .

    This is system table which is in master database .

    IF u are using Vb then u can use sql_DMO .

  • I need to get the server names w/o loggin in to a SQL Server database. Is that possible? This is part of an installer. I won't have a valid username and password at that point.

  • if u want info about active connection u can get those from master.sysprocesses

  • This is you are looking for.

    http://support.microsoft.com/default.aspx?scid=kb;en-us;287737

  • Thanks for your help. Can you please give me an example of the connection statement? I need and ADO connection. right?

  • Do you mean the servers available on a network?

    The following sub requires acces to the SQLDMO object.

    Public Sub PopulateSQLServerCombo(cb As ComboBox, Optional SelectSysServer As Boolean = True)

    On Error Resume Next

    Dim dmo As SQLDMO.Application, lNames As SQLDMO.NameList, Idx As Integer

    Dim sServers As String, Servers() As String

    Dim sComputerName As String

    Set dmo = New SQLDMO.Application

    sComputerName = VBGetComputerName

    With cb

    SendMessage .hwnd, WM_SETREDRAW, 0&, 0&

    Set lNames = dmo.ListAvailableSQLServers

    .Clear

    If lNames.Count > 0 Then

    For Idx = 1 To lNames.Count

    If StrComp(lNames(Idx), "(local)", vbTextCompare) = 0 Then

    .AddItem sComputerName

    Else

    .AddItem lNames(Idx)

    End If

    Next Idx

    Else

    sServers = QueryValue(HKEY_LOCAL_MACHINE, "Software\Microsoft\Microsoft SQL Server", "InstalledInstances", "")

    Servers = Split(sServers, vbNullChar)

    For Idx = LBound(Servers) To UBound(Servers)

    If Len(Servers(Idx)) > 0 Then

    If StrComp(Servers(Idx), "MSSQLSERVER", vbTextCompare) = 0 Then

    .AddItem sComputerName ' Default Instance

    Else

    .AddItem sComputerName & "\" & Servers(Idx) ' Named Instance

    End If

    End If

    Next Idx

    End If

    If SelectSysServer Then SendMessage .hwnd, CB_SELECTSTRING, 0&, ByVal SysServer

    Set lNames = Nothing

    SendMessage .hwnd, WM_SETREDRAW, 1&, 0&

    End With

    Set dmo = Nothing

    End Sub

  • Very simple way to get the SQL Servers on the network is to type

    isql -L;

    from a command line. You'll have to pipe it to a file, then read the file to really make use of the list from within code.

  • My solution intercepts a bug in SQLBrowseConnect that causes the routine to return nothing when no active network connection exist on the computer.

Viewing 10 posts - 1 through 9 (of 9 total)

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