Retrieve SQL Servers

witzulu

Member
Joined
Jul 3, 2004
Messages
20
Programming Experience
3-5
Hi

I would like to add the list of all SQL servers available and add it to a combobox. Could anyone please tell me how to do this or where to go read up on it.
 

kulrom

Well-known member
Joined
May 10, 2005
Messages
2,854
Location
Republic of Macedonia
Programming Experience
10+
Well if your Q is how to list all the SQL Servers programatically in .NET then the answer would be: by using SQLDMO

PHP:
 Dim i As Integer 
Dim oNames As SQLDMO.NameList
Dim oSQLApp As SQLDMO.Application
 
Set oSQLApp = New SQLDMO.Application
Set oNames = oSQLApp.ListAvailableSQLServers()
 
For i = 1 To oNames.Count
'now you can manage oNames.Item(i) /// it is vb6 code but works well in vb.net too
Next

Also you can use netserverenum and even a method using odbc, but however you need to use win api calls or interop.

For next version of vb.net (2005) there will be the SqlDataSourceEnumerator that get a list of all sql servers available to the machine the code was run at.

From .net 2.0 and up, filling a listbox/cpmbobox with the server-names can be as simple as:
PHP:
listBox1.DisplayMember = "ServerName"
listBox1.DataSource = System.Data.Sql.SqlDataSourceEnumerator.Instance.GetDataSources()

Cheers ;)
 
Top Bottom