SqlClientFactory.CreateDataSourceEnumerator Method

Returns a new SqlDataSourceEnumerator.

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

public override DbDataSourceEnumerator CreateDataSourceEnumerator ()
public DbDataSourceEnumerator CreateDataSourceEnumerator ()
public override function CreateDataSourceEnumerator () : DbDataSourceEnumerator
Not applicable.

Return Value

A SqlDataSourceEnumerator.

The following example displays a list of all available SQL Server data sources, using code that could enumerate data sources for any provider.

using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;

class Program
    static void Main()
        // List all SQL Server instances:

        Console.WriteLine("Press any key to continue...");
    private static void ListServers(DbProviderFactory factory)
        // This procedure is provider-agnostic, and can list
        // instances of any provider's servers. Of course, 
        // not all providers can create a data source enumerator,
        // so it's best to check the CanCreateDataSourceEnumerator 
        // property before attempting to list the data sources.
        if (factory.CanCreateDataSourceEnumerator)
            DbDataSourceEnumerator instance =
            DataTable table = instance.GetDataSources();

            foreach (DataRow row in table.Rows)
                    row["ServerName"], row["InstanceName"]);

Windows 98, Windows Server 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 Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions