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 the 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:
  1. DataTable table = DbProviderFactories.GetFactoryClasses();  
  2. foreach(DataRow row in DbProviderFactories.GetFactoryClasses().Rows) {  
  3.     DbProviderFactory providerFactory = DbProviderFactories.GetFactory(row);  
  4.     DbDataSourceEnumerator dsEnum = providerFactory.CreateDataSourceEnumerator();  
  5.     if (dsEnum != null) {  
  6.         DataTable servers = dsEnum.GetDataSources();  
  7.         dataGridView1.DataSource = servers;  
  8.     }  


Similar Articles
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.