SqlDataSourceEnumerator.Instance Property
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets an instance of the SqlDataSourceEnumerator, which can be used to retrieve information about available SQL Server instances.
public:
static property Microsoft::Data::Sql::SqlDataSourceEnumerator ^ Instance { Microsoft::Data::Sql::SqlDataSourceEnumerator ^ get(); };
public static Microsoft.Data.Sql.SqlDataSourceEnumerator Instance { get; }
static member Instance : Microsoft.Data.Sql.SqlDataSourceEnumerator
Public Shared ReadOnly Property Instance As SqlDataSourceEnumerator
Property Value
An instance of the SqlDataSourceEnumerator used to retrieve information about available SQL Server instances.
Examples
The following console application displays a list of all the available SQL Server 2005 instances within the local network. This code uses the Select method to filter the rows in the table returned by the GetDataSources method.
using Microsoft.Data.Sql;
class Program
{
static void Main()
{
// Retrieve the enumerator instance, and
// then retrieve the data sources.
SqlDataSourceEnumerator instance =
SqlDataSourceEnumerator.Instance;
System.Data.DataTable table = instance.GetDataSources();
// Filter the sources to just show SQL Server 2012 instances.
System.Data.DataRow[] rows = table.Select("Version LIKE '11%'");
foreach (System.Data.DataRow row in rows)
{
Console.WriteLine(row["ServerName"]);
}
Console.WriteLine("Press any key to continue.");
Console.ReadKey();
}
}
Remarks
The SqlDataSourceEnumerator class does not provide a constructor. Use the Instance property to retrieve an instance of the class instead.
using Microsoft.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("============================");
}
}
}