本文整理匯總了C#中System.Data.SqlClient.SqlClientFactory.CreateDataSourceEnumerator方法的典型用法代碼示例。如果您正苦於以下問題:C# SqlClientFactory.CreateDataSourceEnumerator方法的具體用法?C# SqlClientFactory.CreateDataSourceEnumerator怎麽用?C# SqlClientFactory.CreateDataSourceEnumerator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。
在下文中一共展示了SqlClientFactory.CreateDataSourceEnumerator方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
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"]);
}
}
}
}