SqlClientFactory.CanCreateDataSourceEnumerator Vlastnost

Definice

Získá hodnotu, která označuje, zda SqlDataSourceEnumerator lze vytvořit.Gets a value that indicates whether a SqlDataSourceEnumerator can be created.

public:
 virtual property bool CanCreateDataSourceEnumerator { bool get(); };
public override bool CanCreateDataSourceEnumerator { get; }
member this.CanCreateDataSourceEnumerator : bool
Public Overrides ReadOnly Property CanCreateDataSourceEnumerator As Boolean

Hodnota vlastnosti

Boolean

true Pokud je SqlDataSourceEnumerator možné vytvořit, jinak false .true if a SqlDataSourceEnumerator can be created; otherwise, false.

Příklady

Následující příklad zobrazí seznam všech dostupných SQL Server zdrojů dat pomocí kódu, který může vytvořit výčet zdrojů dat pro libovolného poskytovatele.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:
        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"]);
            }
        }
    }
}
Imports System.Data
Imports System.Data.Common
Imports System.Data.SqlClient

Module Module1
    Sub Main()
        ' List all SQL Server instances:
        ListServers(SqlClientFactory.Instance)

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

    Private Sub ListServers(ByVal factory As DbProviderFactory)
        ' 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 Then
            Dim instance As DbDataSourceEnumerator = _
             factory.CreateDataSourceEnumerator
            Dim table As System.Data.DataTable = instance.GetDataSources()

            Dim row As DataRow
            For Each row In table.Rows
                Console.WriteLine("{0}\{1}", _
                 row("ServerName"), row("InstanceName"))
            Next
        End If
    End Sub
End Module

Poznámky

DbProviderFactoryTřída poskytuje CanCreateDataSourceEnumerator vlastnost, aby dědice mohli určit, zda mohou poskytnout enumerátor zdroje dat.The DbProviderFactory class provides the CanCreateDataSourceEnumerator property so that inheritors can indicate whether they can provide a data source enumerator. SqlClientFactoryZobrazí tuto vlastnost, ale její hodnota je vždy true .The SqlClientFactory displays this property, but its value is always true.

Platí pro