DbProviderFactory factory = DbProviderFactories.GetFactory("System.Data.SqlClient");

if (factory.CanCreateDataSourceEnumerator)

{

DbDataSourceEnumerator dataSourceEnumerator = factory.CreateDataSourceEnumerator();

if (dataSourceEnumerator != null)

{

// Here is the list of SQL Servers

DataTable dt = dataSourceEnumerator.GetDataSources();

dataGridView1.DataSource = dt;

}

}

Advertisements