Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I found the following code to show instances on SQL Servers on a network:

VB
Private Sub DisplayData(ByVal table As DataTable)
   For Each row As DataRow In table.Rows
        For Each col As DataColumn In table.Columns
            Debug.Print("{0} = {1}", col.ColumnName, row(col))
        Next
        Debug.Print("============================")
   Next
End Sub
Private Sub Form1_Load(ByVal sender As Object, _
                       ByVal e As System.EventArgs) _
            Handles Me.Load
   ' Retrieve the enumerator instance and then the data.
   Dim instance As SqlDataSourceEnumerator = _
            SqlDataSourceEnumerator.Instance
   Dim table As System.Data.DataTable = instance.GetDataSources()
   ' Display the contents of the table.
   DisplayData(table)
   'Console.WriteLine("Press any key to continue.")
   'Console.ReadKey()
End Sub


This code returns the following to the Intermediate window:
ServerName = LT-MRM-1
InstanceName =
IsClustered =
Version =
All I want to do is make a list of server names in a combobox, but I can't find a simple solution.
Can someone point me in the right direction?

[Modified: added code formatting]
Posted
Updated 18-Mar-10 5:26am
v3

1 solution

Is your problem that it doesn't show all the Sql Servers or that you don't know how to bind the datatable to a combobox?

If it is the first;
You need to have SQL Server Browser[^] runing on all the computers with Sql Server on them, and you need port 1434 open on those computers.


For the second;
MIDL
comboBox1.DataSource = table;
comboBox1.ValueMember = "ServerName";
comboBox1.DisplayMember = "ServerName";
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900