January 29, 2004 at 4:31 am
I am building a VB.NET app and would like to populate a combo box with the names of SQL Servers available on the company network. How do I retrieve a list of available SQL Servers?
January 29, 2004 at 4:55 am
Hm, not sure if it's the same in VB.Net, but in VB6 you can use
Private Sub Form_Load()
oBorder.FlatBorder (lstServer.hWnd)
Set oSQLApplication = New SQLDMO.Application
Set oNameList = oSQLApplication.ListAvailableSQLServers
For i = 1 To oNameList.Count
lstServer.AddItem oNameList.Item(i)
Next i
End Sub
Of course, you need a reference to the SQLDMO Object Library.
For SQL DMO in general I would recommend looking at Andy Warrens' articles on that topic, which you find here
http://www.sqlservercentral.com/columnists/awarren/allarticles.asp
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
January 29, 2004 at 7:32 am
Thanks Frank. I was able to get it from what you gave me. Here is what works in VB.NET
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim oSQLApplication As New SQLDMO.Application
Dim oNameList As SQLDMO.NameList
oNameList =
CType(oSQLApplication.ListAvailableSQLServers(), SQLDMO.NameList)
Dim i As Integer
For i = 1 To oNameList.Count
ListBox1.Items.Add(oNameList.Item(i))
Next
End Sub
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply