Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

SqlDataSourceEnumerator.Instance Property

Gets an instance of the SqlDataSourceEnumerator, which can be used to retrieve information about available SQL Server instances.

Namespace:  System.Data.Sql
Assembly:  System.Data (in System.Data.dll)
public static SqlDataSourceEnumerator Instance { get; }

Property Value

Type: System.Data.Sql.SqlDataSourceEnumerator
An instance of the SqlDataSourceEnumerator used to retrieve information about available SQL Server instances.

The SqlDataSourceEnumerator class does not provide a constructor. Use the Instance property to retrieve an instance of the class instead.

The following console application displays a list of all the available SQL Server 2005 instances within the local network. This code uses the Select method to filter the rows in the table returned by the GetDataSources method.

using System.Data.Sql;

class Program
{
  static void Main()
  {
    // Retrieve the enumerator instance, and
    // then retrieve the data sources.
    SqlDataSourceEnumerator instance =
      SqlDataSourceEnumerator.Instance;
    System.Data.DataTable table = instance.GetDataSources();

    // Filter the sources to just show SQL Server 2005 instances.
    System.Data.DataRow[] rows = table.Select("Version LIKE '9%'");
    foreach (System.Data.DataRow row in rows)
    {
      Console.WriteLine(row["ServerName"]);
    }
    Console.WriteLine("Press any key to continue.");
    Console.ReadKey();
  }
}

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.