8.13. Discover All Instances of SQL Server on Your Network

Problem

You need to obtain a list of all instances of SQL Server 2000 or SQL Server 2005 that are accessible on the network.

Solution

Use the GetDataSources method of the System.Data.Sql.SqlDataSourceEnumerator class.

NOTE

Your code needs to be granted FullTrust to be able to execute the GetDataSources method.

How It Works

The SqlDataSourceEnumerator class makes it easy to enumerate the SQL Server instances accessible on the network. Since this class does not have an accessible constructor, you must use the Shared property SqlDataSourceEnumerator.Instance to return an instance of the class. You then use the GetDataSources method to return a System.Data.DataTable that contains a set ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.