Enumerating Installed Data Providers 

By using the GetFactoryClasses method, you can enumerate data providers that are installed on your computer. These data providers are listed in the machine.config file.

The results are returned as a DataTable named DbProviderFactories that contains these columns:

Column ordinal Column name Example output Description

0

Name

Odbc Data Provider

Readable name for the data provider

1

Description

.Net Framework Data Provider for Odbc

Readable description of the data provider

2

InvariantName

System.Data.Odbc

Name that can be used programmatically to refer to the data provider

3

AssemblyQualifiedName

System.Data.Odbc.OdbcFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

Fully-qualified name of the factory class, which contains enough information to instantiate the object.

The following example enumerates data providers that are installed on the local computer.

Imports System.Data.Common

Module Module1

  Sub Main()
    Dim providerTable As DataTable = _
     DbProviderFactories.GetFactoryClasses()
    ' Enumerate the available providers:
    For Each row As DataRow In providerTable.Rows
      For Each col As DataColumn In providerTable.Columns
        Console.WriteLine("{0}: {1}", col.ColumnName, _
         row(col.ColumnName))
      Next
    Next

    Console.WriteLine()
    Console.WriteLine("Press any key to continue...")
    Console.ReadKey()
  End Sub

End Module
using System;
using System.Data;
using System.Data.Common;

class Program
{
  static void Main()
  {
    DataTable providerTable = DbProviderFactories.GetFactoryClasses();

    // Enumerate the available providers:
    foreach (DataRow row in providerTable.Rows)
    {
      foreach (DataColumn col in providerTable.Columns)
      {
        Console.WriteLine("{0}: {1}", col.ColumnName, row[col.ColumnName]);
      }
    }

    Console.WriteLine();
    Console.WriteLine("Press any key to continue...");
    Console.ReadKey();
  }
}

See Also

Concepts

Writing Provider Independent Code in ADO.NET