Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: How can get the available SQL SERVER NAMES in network?


Message #1 by "Hemantha Kumar Reddy K" <khkreddy@y...> on Wed, 12 Dec 2001 09:03:02
This is a multi-part message in MIME format.

------=_NextPart_000_0258_01C18334.2AD05940
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

HI,

Private Function AvailableSQLServers() As String()
'***********************************************
'PURPOSE:       Returns array list name of all SQL Servers
'               on the network that are visible to the
'               machine
'
'RETURNS:       String array containing names of all
'               available SQL Servers (or an array with one
'               element containing empty string if no
'               SQL Servers are available/visible)
              
'REQUIRES:      Reference to Microsoft SQLDMO object library
'               VB6 Because array is returned
'               Assumes Option Base is not set to 1
'               If you don't have VB6, and/or Option Base 1
'               is set, it should not be very hard to modify
'               this code for you own purposes

'EXAMPLE:
'Dim sServers() As String
'Dim iCtr As Integer

'sServers =3D AvailableSQLServers
'If sServers(0) =3D "" Then
'    MsgBox "No SQL Servers Available"
'Else
'    For iCtr =3D 0 To UBound(sServers)
'       Debug.Print sServers(iCtr)
'   Next
'End If
'***********************************************
Dim oServer As New SQLDMO.Application
Dim oNameList As SQLDMO.NameList
Dim iElement As Integer
Dim sAns() As String
Dim lCtr As Long, lCount As Long

On Error GoTo ErrorHandler

ReDim sAns(0) As String
Set oNameList =3D oServer.ListAvailableSQLServers

With oNameList
    lCount =3D .Count
    If lCount > 0 Then
        For lCtr =3D 1 To .Count
            iElement =3D IIf(sAns(0) =3D "", 0, UBound(sAns) + 1)
            ReDim Preserve sAns(iElement) As String
            sAns(iElement) =3D oNameList.Item(lCtr)
        Next
    End If
End With

AvailableSQLServers =3D sAns
Exit Function

ErrorHandler:
'Return array with one empty element on error
ReDim sAns(0) As String
AvailableSQLServers =3D sAns
End Function


Hope this helps.
Paul

----- Original Message -----
From: Gopalakrishnan <mailto:ntg@s...> 
To: professional vb <mailto:pro_vb@p...> 
Sent: Wednesday, December 12, 2001 5:02 PM
Subject: [pro_vb] Re: How can get the available SQL SERVER NAMES in
network?

Use SQL-DMO.

N.T.GOPALAKRISHNAN

----- Original Message -----
From: Hemantha Kumar  <mailto:khkreddy@y...> Reddy K
To: professional vb <mailto:pro_vb@p...> 
Sent: Wednesday, December 12, 2001 9:03 AM
Subject: [pro_vb] How can get the available SQL SERVER NAMES in 
network?

hi all,

I want to list out the SQL Server Names and their Databases available 
in

network into two Combo Boxes. How can get the available SQL SERVER
Names?


Thanks
Hemanth
---
Change your mail options at http://p2p.wrox.com/manager.asp
<http://p2p.wrox.com/manager.asp>  or
<mailto:$subst('Email.Unsub')> .






  Return to Index