Solved

How many sql server in the network?

Posted on 2002-06-27
2
130 Views
Last Modified: 2012-05-04
Hi All,

How would I know how many SQL servers (server name) in the network?

Sean.
0
Comment
Question by:whsean
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
xSinbad earned 50 total points
ID: 7115535
Here is some code used to detect servers on the network;



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()
    '
    ' 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 = "placeYourDomainNameHere" & 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

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7964622
Hi whsean,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept xSinbad's comment(s) as an answer.

whsean, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.
==========
DanRollins -- EE database cleanup volunteer
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question