Using SqlDataSourceEnumerator class in the System.Data.Sql namespace, it is easy for developers to enumerate and get a list of existing visible Microsoft SQL Server database instances within a network.
Using the Instance property of the SqlDataSourceEnumerator class you can create an instance of the SqlDataSourceEnumerator object that can be used to retrieve information about available SQL Server instances. Microsoft SQL Server 2000, SQL Server 2005 and SQL Server 2008 (Katmai) database instances within a network can be listed using this new class "SqlDataSourceEnumerator". GetDataSources() method of the SqlDataSourceEnumerator class returns information in a DataTable object that can be used to display data about the retrieved SQL database instances on a DataGridView or in a ComboBox object. Import the Imports System.Data.Sql if it is not imported within the project by default. Imports System.Data.Sql Calling the SqlDataSourceEnumerator.Instance will get the public shared instance of SqlDataSourceEnumerator class whose GetDataSources() method will be used to return information about the SQL Servers in a DataTable object. Dim dataTable As DataTable = SqlDataSourceEnumerator.Instance.GetDataSources() After the information about SQL Servers is stored and retrieved using the DataTable object instance, you can bind this data to a DataGridView object as follows; DataGridView1.DataSource = dataTable As you see, DataTable that is returned by the GetDataSources() method of the SqlDataSourceEnumerator class includes the following columns:
Imports System.Data.Sql
Dim dataTable As DataTable = SqlDataSourceEnumerator.Instance.GetDataSources()
DataGridView1.DataSource = dataTable
For Each datarow As DataRow In dataTable.Rows Dim datasource As String = datarow("ServerName").ToString If Not datarow("InstanceName") Is DBNull.Value Then datasource &= String.Format("\{0}", datarow("InstanceName")) End If ComboBox1.Items.Add(datasource) Next
BlinkList Del.icio.us Digg Furl Simpy Spurl DZone ma.gnolia Shadows