Compartilhar via


SqlClientFactory.CreateDataSourceEnumerator Método

Definição

Retorna um novo SqlDataSourceEnumerator .

public:
 override System::Data::Common::DbDataSourceEnumerator ^ CreateDataSourceEnumerator();
public override System.Data.Common.DbDataSourceEnumerator CreateDataSourceEnumerator ();
abstract member CreateDataSourceEnumerator : unit -> System.Data.Common.DbDataSourceEnumerator
override this.CreateDataSourceEnumerator : unit -> System.Data.Common.DbDataSourceEnumerator
override this.CreateDataSourceEnumerator : unit -> System.Data.Common.DbDataSourceEnumerator
Public Overrides Function CreateDataSourceEnumerator () As DbDataSourceEnumerator

Retornos

Um novo enumerador da fonte de dados.

Exemplos

O exemplo a seguir exibe uma lista de todas as fontes de dados SQL Server disponíveis, usando código que pode enumerar fontes de dados para qualquer provedor.

// <Snippet1>
using System;
using System.Data;
using System.Data.Common;
using Microsoft.Data.SqlClient;

class Program
{
    static void Main()
    {
        // List all SQL Server instances:
        ListServers(SqlClientFactory.Instance);

        Console.WriteLine();
        Console.WriteLine("Press any key to continue...");
        Console.ReadKey();
    }
    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 =
                factory.CreateDataSourceEnumerator();
            DataTable table = instance.GetDataSources();

            foreach (DataRow row in table.Rows)
            {
                Console.WriteLine("{0}\\{1}",
                    row["ServerName"], row["InstanceName"]);
            }
        }
    }
}
// </Snippet1>

Aplica-se a