Results 1 to 3 of 3

Thread: Server

  1. #1

    Thread Starter
    Fanatic Member faisalkm's Avatar
    Join Date
    Oct 2000
    Location
    Germany
    Posts
    752

    Unhappy

    Hi Guys,

    Is there any way to get all available sqlservers running on a network?
    Faisal
    Faisal Muhammed
    Homepage:I Started making it in 1994 ...Still Under Construction
    Using

    Visual Basic 6.0 Enterprise SP5
    Embedded Visual Basic 3.0
    SQL Server 2000
    Windows 2000 Proff
    Delphi 6.0


    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

  2. #2
    Addicted Member S@NSIS's Avatar
    Join Date
    Aug 2000
    Location
    Stoke-On-Trent, England
    Posts
    243
    Hi,
    Try This: (put in a module and access it from whereever)

    Code:
    Option Explicit
    
    Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long) As Long
    
    Private Declare Function NetServerEnum Lib "netapi32" ( _
            strServername As Any, _
            ByVal level As Long, _
            bufptr As Long, _
            ByVal prefmaxlen As Long, _
            entriesread As Long, _
            totalentries As Long, _
            ByVal servertype As Long, _
            strDomain As Any, _
            resumehandle As Long) As Long
    
    
    Private Declare Function NetApiBufferFree Lib "Netapi32.dll" _
    (ByVal lpBuffer As Long) As Long
    
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
    (Destination As Any, Source As Any, ByVal Length As Long)
    
    Private Const SV_TYPE_SERVER As Long = &H2
    Private Const SV_TYPE_SQLSERVER As Long = &H4
    
    Private Type SV_100
      platform As Long
      name As Long
    End Type
    
    Public Sub GetSQLServers(DomainName As String)
        '
        ' You could change this to be a function returning
        ' a list of the SQL servers in a ADOR Recordset or an array etc.
        '
        ' At present, it just does a debug.print of all the
        ' SQL servers on the network.
        '
        '
        Dim l As Long
        Dim entriesread As Long
        Dim totalentries As Long
        Dim hREsume As Long
        Dim bufptr As Long
        Dim level As Long
        Dim prefmaxlen As Long
        Dim lType As Long
        Dim domain() As Byte
        Dim i As Long
        Dim sv100 As SV_100
    
        level = 100
        prefmaxlen = -1
    
        lType = SV_TYPE_SQLSERVER
        domain = DomainName & vbNullChar
        l = NetServerEnum(ByVal 0&, _
                level, _
                bufptr, _
                prefmaxlen, _
                entriesread, _
                totalentries, _
                lType, _
                domain(0), _
                hREsume)
    
        If l = 0 Or l = 234& Then
            For i = 0 To entriesread - 1
                CopyMemory sv100, ByVal bufptr, Len(sv100)
                Debug.Print Pointer2stringw(sv100.name)
                bufptr = bufptr + Len(sv100)
            Next i
        End If
        NetApiBufferFree bufptr
        '
    End Sub
    
    Private Function Pointer2stringw(ByVal l As Long) As String
        Dim buffer() As Byte
        Dim nLen As Long
        '
        nLen = lstrlenW(l) * 2
        If nLen Then
            ReDim buffer(0 To (nLen - 1)) As Byte
            CopyMemory buffer(0), ByVal l, nLen
            Pointer2stringw = buffer
        End If
    End Function
    Hope this helps

    Shaun
    Web/Application Developer
    VB6 Ent (SP5), Win 2000,SQL Server 2000

  3. #3

    Thread Starter
    Fanatic Member faisalkm's Avatar
    Join Date
    Oct 2000
    Location
    Germany
    Posts
    752

    Unhappy

    Thanks I got it before.But I meant something else in my mind and wrote something. I will tell u what i want.

    I'm getting all available sqlserver names. But if I stop an sql server and then run this API still i get the sql server name. I want to get all SQl Servers which are running in the domain. I hope u got my point.

    Faisal
    Faisal Muhammed
    Homepage:I Started making it in 1994 ...Still Under Construction
    Using

    Visual Basic 6.0 Enterprise SP5
    Embedded Visual Basic 3.0
    SQL Server 2000
    Windows 2000 Proff
    Delphi 6.0


    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

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