Smallville
Member
- Joined
- Jul 7, 2005
- Messages
- 7
- Programming Experience
- 1-3
Hi,
I am using the Netapi32 windows api to get all SQL Servers running on the network. Unfortunately this is not working. Again this piece of code used to work on the
I am sure I did somehting wrong but don't know what. Does anyone has any idea of what it is?
Thanking you in advance,
Kind Regards,
Somebody save me......
I am using the Netapi32 windows api to get all SQL Servers running on the network. Unfortunately this is not working. Again this piece of code used to work on the
VB.NET:
Private Declare Function NetServerEnum Lib "Netapi32.dll" ( _
ByVal strServerName As String, _
ByVal level As Integer, _
ByRef bufptr As Integer, _
ByVal prefmaxlen As Integer, _
ByRef entriesread As Integer, _
ByRef totalentries As Integer, _
ByRef servertype As Integer, _
ByVal strDomain As String, _
ByRef resumehandle As Integer) As Integer
VB.NET:
'Using the NetApi to perform this task
Private Declare Function NetApiBufferFree Lib "Netapi32.dll" ( _
ByVal lpBuffer As Integer) As Integer
VB.NET:
Public Sub GetSQLServers()
'This function will return all the SQL Servers available
'within the default domain
Try
'Variables to specify the parameters for the SQL Server
Dim l As Integer
Dim entriesread As Integer
Dim totalentries As Integer
Dim hREsume As Integer
Dim bufptr As Integer
Dim level As Integer
Dim prefmaxlen As Integer
Dim lType As Integer
Dim domain() As Byte
Dim i As Integer
Dim sv100 As SV_100
level = 100
prefmaxlen = &HFFFFFFFF
'Locate only SQLServers
lType = SV_TYPE_SQLSERVER
'Setting the required parameters
l = NetServerEnum(CStr(0), level, bufptr, prefmaxlen, entriesread, totalentries, SV_TYPE_SQLSERVER, CStr(0), hREsume)
'The NetSErverEnum returns a long type value.
'If that value is 0 or 234& then,
'For no entries read to all entries read
'Add the sql server name to the collection.
'If the returned value is not 0 or 234&, then
'Prompt user that no server was found.
If l = 0 Or l = 234 Then
For i = 0 To entriesread - 1
CopyMemory(sv100, bufptr, Len(sv100))
'Adding the sql server name to the collection
colSQLServers.Add(Trim(Pointer2stringw(sv100.name)))
bufptr = bufptr + Len(sv100)
Next i
End If
'Settings for establishing a connection to the local server
colSQLServers.Add("(local)")
NetApiBufferFree(bufptr)
Catch ex As Exception
MsgBox(ex.ToString, MsgBoxStyle.OKOnly + MsgBoxStyle.Critical, "Exception")
'Prompt user with error message
ErrorControl(Err.Number)
End Try
End Sub
I am sure I did somehting wrong but don't know what. Does anyone has any idea of what it is?
Thanking you in advance,
Kind Regards,
Somebody save me......