Results 1 to 4 of 4

Thread: Unable to retrieve list of SQL Servers

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Posts
    21

    Unable to retrieve list of SQL Servers

    I have an SQL 7 server (MSDE Version) running on W2k Workstation. NetBios is installed.

    When I try to get a list of SQL servers using the "ListAvailableSQLServers" command it returns 0 results. Not even the local.

    When I type isql -L from the command prompt I get the following error:

    Locally configured servers:
    -- NONE --
    Net-Library version does not support server enumeration.

    Another of my SQL Servers can see other servers but, cannot see the one giving me the problem.

    Any suggestions?

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Use SQLDMO, it provides a way for retireving a list of SQL Severs runing.
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Feb 2002
    Posts
    21
    I am using SQLDMO.

    That is where the ListAvailableSQLServer function comes from.

  4. #4
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    Here is a method using API. I think I originally got this from Hack or Peet or someone. Anyway it's not my code:
    VB Code:
    1. Private Const SV_TYPE_SQLSERVER As Long = &H4 ' SQL Server
    2.  
    3. Const ERROR_SUCCESS = 0
    4. Const ERROR_MORE_DATA = 234
    5. Const SIZE_SI_101 = 24
    6.  
    7. Private Type SERVER_INFO_101
    8.    dwPlatformId As Long
    9.    lpszServerName As Long
    10.    dwVersionMajor As Long
    11.    dwVersionMinor As Long
    12.    dwType As Long
    13.    lpszComment As Long
    14. End Type
    15.  
    16. Private Declare Sub RtlMoveMemory Lib "kernel32" ( _
    17.    hpvDest As Any, ByVal hpvSource As Long, ByVal cbCopy As Long)
    18.  
    19. Private Declare Function NetServerEnum Lib "netapi32.dll" ( _
    20.    ByVal servername As String, _
    21.    ByVal Level As Long, _
    22.    BUFFER As Long, _
    23.    ByVal PrefMaxLen As Long, _
    24.    entriesread As Long, _
    25.    totalentries As Long, _
    26.    ByVal ServerType As Long, _
    27.    ByVal domain As String, _
    28.    resumehandle As Long) As Long
    29.  
    30. Private Declare Function NetApiBufferFree Lib "netapi32.dll" ( _
    31.    BufPtr As Any) As Long
    32.  
    33. Private Declare Function lstrcpyW Lib "kernel32" ( _
    34.    ByVal lpszDest As String, ByVal lpszSrc As Long) As Long
    35.  
    36. Public Sub GetServerList()
    37. 'This sub scans the local network for all Servers running SQL Server.  It outputs the list to a combo box
    38.    Dim pszTemp As String
    39.    Dim pszServer As String
    40.    Dim pszDomain As String
    41.    Dim lLevel As Long
    42.    Dim i As Long
    43.    Dim BufPtr As Long
    44.    Dim TempBufPtr As Long
    45.    Dim PrefMaxLen As Long
    46.    Dim lEntriesRead As Long
    47.    Dim lTotalEntries As Long
    48.    Dim lServerType As Long
    49.    Dim lResumeHandle As Long
    50.    Dim lRes As Long
    51.    Dim ServerInfo As SERVER_INFO_101
    52.  
    53.    pszServer = vbNullString
    54.    pszDomain = vbNullString
    55.  
    56.    lLevel = 101
    57.    BufPtr = 0
    58.    lPrefMaxLen = &HFFFFFFFF
    59.    lEntriesRead = 0
    60.    lTotalEntries = 0
    61.    lServerType = SV_TYPE_SQLSERVER
    62.    lResumeHandle = 0
    63.  
    64.    Do
    65.       lRes = NetServerEnum(pszServer, lLevel, BufPtr, _
    66.                       lPrefMaxLen, lEntriesRead, lTotalEntries, _
    67.                       lServerType, pszDomain, lResumeHandle)
    68.       If ((lRes = ERROR_SUCCESS) Or (lRes = ERROR_MORE_DATA)) And _
    69.          (lEntriesRead > 0) Then
    70.          TempBufPtr = BufPtr
    71.          For i = 1 To lEntriesRead
    72.             RtlMoveMemory ServerInfo, TempBufPtr, SIZE_SI_101
    73.             'Add Records to ComboBox
    74.             Combo1.AddItem PointerToString(ServerInfo.lpszServerName)
    75.              
    76.             TempBufPtr = TempBufPtr + SIZE_SI_101
    77.          Next i
    78.       Else
    79.          MsgBox "NetServerEnum failed: " & lRes
    80.       End If
    81.       NetApiBufferFree (BufPtr)
    82.    Loop While lEntriesRead < lTotalEntries
    83.    
    84. End Sub
    85.  
    86. Public Function PointerToString(lpszString As Long) As String
    87.    ' converts a pointer to a string to a VB string
    88.    Dim lpszStr1 As String
    89.    Dim lpszStr2 As String
    90.    Dim lRes     As Long
    91.    
    92.    lpszStr1 = String(1000, "*")
    93.    lRes = lstrcpyW(lpszStr1, lpszString)
    94.    lpszStr2 = (StrConv(lpszStr1, vbFromUnicode))
    95.    PointerToString = Left(lpszStr2, InStr(lpszStr2, Chr$(0)) - 1)
    96. End Function

    You can try it and see if it works.
    Chris

    Master Of My Domain
    Got A Question? Look Here First

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