Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

SqlDataSourceEnumerator.GetDataSources Method

Note: This method is new in the .NET Framework version 2.0.

Retrieves a DataTable containing information about all visible SQL Server 2000 or SQL Server 2005 instances.

Namespace: System.Data.Sql
Assembly: System.Data (in system.data.dll)

public override DataTable GetDataSources ()
public DataTable GetDataSources ()
public override function GetDataSources () : DataTable

Return Value

Returns a DataTable containing information about the visible SQL Server instances.

The table returned by this method contains the following columns, all of which contain strings:

Column

Description

ServerName

Name of the server.

InstanceName

Name of the server instance. Blank if the server is running as the default instance.

IsClustered

Indicates whether the server is part of a cluster.

Version

Version of the server (8.00.x for SQL Server 2000, and 9.00.x for SQL Server 2005).

NoteNote

Due to the nature of the mechanism used by SqlDataSourceEnumerator to locate data sources on a network, the method will not always return a complete list of the available servers, and the list might not be the same on every call. If you plan to use this function to let users select a server from a list, make sure that you always also supply an option to type in a name that is not in the list, in case the server enumeration does not return all the available servers. In addition, this method may take a significant amount of time to execute, so be careful about calling it when performance is critical.

The following console application retrieves information about all the visible SQL Server instances and displays the information in the console window.

using System.Data.Sql;

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

    // Display the contents of the table.
    DisplayData(table);

    Console.WriteLine("Press any key to continue.");
    Console.ReadKey();
  

  private static void DisplayData(System.Data.DataTable table)
  {
    foreach (System.Data.DataRow row in table.Rows)
    {
      foreach (System.Data.DataColumn col in table.Columns)
      {
        Console.WriteLine("{0 = {1", col.ColumnName, row[col]);
      
      Console.WriteLine("============================");
    
  

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2015 Microsoft