Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Return Names of SQL Servers on network? 1

Status
Not open for further replies.

LFCfan

Programmer
Nov 29, 2002
3,015
0
0
GB
Hi folks

I've got a dropdownlist on an ASP.NET page which i would like to populate with a list of servers running SQL Server that are currently active on the network - basically like the list brought back in the "SQL Servers" dropdown in the form that appears when you click on File/Connect in Query Analyser.

Can anyone point me in the right direction?
Or am i better off posting in the ASP.NET forum?

Many thanks
LFCfan

 
Possibly not the ideal forum, but here's some VB6 code for it - can't be that different:

Private Sub listSQLServers()
Dim oSQLServer As SQLDMO.Application
Dim i As Integer
Dim sRetValue As String
Set oSQLServer = New SQLDMO.Application
Dim List As NameList
Set List = oSQLServer.ListAvailableSQLServers
For i = 1 To List.Count
Me.cboServers.AddItem List(i)
Next
Set List = Nothing
Set oSQLServer = Nothing
End Sub

I use this in a little scripting program I wrote, called on form load.

HTH,

Graham
 
Cheers Graham
That should get me started anyway!
 
Thanks again Graham - with the following tweaks in .NET, it's working a treat!

Private Sub mListSQLServers()
Dim oSQLServer As New SQLDMO.Application()
Dim i As Int32

For i = 1 To oSQLServer.ListAvailableSQLServers.Count
Me.cboSourceServer.Items.Add(oSQLServer.ListAvailableSQLServers.Item(i))
Next
oSQLServer = Nothing
End Sub
 
Had a quick scant myself - you can do this too:

Private Function listSQLServers()
Dim oSQLServer As SQLDMO.Application
oSQLServer = New SQLDMO.Application()
cboServers.DataSource = oSQLServer.ListAvailableSQLServers
cboServers.DataBind()

End Function

Cool huh?

All the best,

Graham
 
oops, should have really thought of doing it that way myself... oh well, hopefully i'll be more with it next time!

Thanks again!
M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top