Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Comment reconnaitre les serveusrs SQL sur un Réseau TCP/IP

1 réponse
Avatar
mb
Bonjour
Comment reconnaitre les serveurs SQL sur un Réseau TCP/IP
Merci

1 réponse

Avatar
mb
Parfait
J'ai pas bien compris le programme mais il tourne


"Emmanuel COCHERIL" a écrit dans le message de
news:bk9n6d$1q5g$
Bonjour mb

Comme ça, en appelant une API.
J'utilise ce code pour scanner les serveurs SQL sur un LAN (tcpip)

Bonne journée

Emmanuel


'Windows type used to call the Net API
Private Const MAX_PREFERRED_LENGTH As Long = -1
Private Const NERR_SUCCESS As Long = 0&
Private Const ERROR_MORE_DATA As Long = 234&
Private Const SV_TYPE_SQLSERVER As Long = &H4

'Mask applied to svX_version_major in
'order to obtain the major version number.
Private Const MAJOR_VERSION_MASK As Long = &HF

Private Type SERVER_INFO_100
sv100_platform_id As Long
sv100_name As Long
End Type

Private Declare Function NetServerEnum Lib "netapi32" (ByVal servername As
Long, ByVal level As Long, buf As Any, _
ByVal prefmaxlen As Long, entriesread As Long, totalentries As Long,
ByVal servertype As Long, ByVal domain As Long, _
resume_handle As Long) As Long

Private Declare Function NetApiBufferFree Lib "netapi32" (ByVal Buffer As
Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pTo


As
Any, uFrom As Any, ByVal lSize As Long)
Private Declare Function lstrlenW Lib "kernel32" (ByVal lpString As Long)


As
Long



Private Function GetServersSQL(sDomain As String, ByRef ListeServers As
String) As Long
On Error GoTo goErreur
Dim strServeurs As String

'lists all servers of the specified type
'that are visible in a domain.

Dim bufptr As Long
Dim dwEntriesread As Long
Dim dwTotalentries As Long
Dim dwResumehandle As Long
Dim se100 As SERVER_INFO_100
Dim success As Long
Dim nStructSize As Long
Dim cnt As Long

nStructSize = LenB(se100)

'Call passing MAX_PREFERRED_LENGTH to have the
'API allocate required memory for the return values.
'
'The call is enumerating all machines on the
'network (SV_TYPE_ALL); however, by Or'ing
'specific bit masks for defined types you can
'customize the returned data. For example, a
'value of 0x00000003 combines the bit masks for
'SV_TYPE_WORKSTATION (0x00000001) and
'SV_TYPE_SERVER (0x00000002).
'
'dwServerName must be Null. The level parameter
'(100 here) specifies the data structure being
'used (in this case a SERVER_INFO_100 structure).
'
'The domain member is passed as Null, indicating
'machines on the primary domain are to be retrieved.
'If you decide to use this member, pass
'StrPtr("domain name"), not the string itself.

success = NetServerEnum(0&, 100, bufptr, MAX_PREFERRED_LENGTH, _
dwEntriesread, dwTotalentries,


SV_TYPE_SQLSERVER,
0&, dwResumehandle)


'if all goes well
If success = NERR_SUCCESS And _
success <> ERROR_MORE_DATA Then

'loop through the returned data, adding each
'machine to the list
For cnt = 0 To dwEntriesread - 1

'get one chunk of data and cast
'into an SERVER_INFO_100 struct
'in order to add the name to a list

CopyMemory se100, ByVal bufptr + (nStructSize * cnt), nStructSize
If Len(strServeurs) > 0 Then strServeurs = strServeurs & ";"
strServeurs = strServeurs &
GetPointerToByteStringW(se100.sv100_name)
Next

End If

'clean up regardless of success
Call NetApiBufferFree(bufptr)

'return entries as sign of success
GetServersSQL = dwEntriesread
ListeServers = strServeurs

goSortie:
Exit Function

goErreur:
MsgBox Err.Number & " - " & Err.Description
GetServersSQL = -1
Resume goSortie
End Function


Private Function GetPointerToByteStringW(ByVal dwData As Long) As String
On Error Resume Next

Dim tmp() As Byte
Dim tmplen As Long

If dwData <> 0 Then
tmplen = lstrlenW(dwData) * 2
If tmplen <> 0 Then
ReDim tmp(0 To (tmplen - 1)) As Byte
CopyMemory tmp(0), ByVal dwData, tmplen
GetPointerToByteStringW = tmp
End If
End If
End Function



"mb" a écrit dans le message de news:
#
> Bonjour
> Comment reconnaitre les serveurs SQL sur un Réseau TCP/IP
> Merci
>
>