Getting Data Providers Details in ADO.NET 2.0

In ADO.NET 2.0, there is a new addition of DB provider factory classes, which allow developers to get the information about the data providers available (installed) on a machine.

DbProviderFactories class's GetFactoryClasses method returns all the available data providers and GetFactory method returns the information about that specific provider.

DbProviderFactory.CreateDataSourceEnumerator returns enumerations of the provider and DbDataSourceEnumerator.GetDataSources returns all the available data sources.

The following code shows how to use these classes and methods:

DataTable table = DbProviderFactories.GetFactoryClasses();
foreach (DataRow row in DbProviderFactories.GetFactoryClasses().Rows)
DbProviderFactory providerFactory = DbProviderFactories.GetFactory(row);
DbDataSourceEnumerator dsEnum = providerFactory.CreateDataSourceEnumerator();
if (dsEnum != null)
DataTable servers = dsEnum.GetDataSources();
dataGridView1.DataSource = servers;