Export (0) Print
Expand All
3 out of 5 rated this helpful - Rate this topic

Enumerating Installed Data Providers 

.NET Framework 2.0

Each installed data provider that supports a factory-based class registers configuration information in the machine.config file on the local computer in the DbProviderFactories section. The following configuration file fragment shows the syntax and format for System.Data.SqlClient.

<system.data>
  <DbProviderFactories>
    <add name="SqlClient Data Provider"
     invariant="System.Data.SqlClient" 
     description=".Net Framework Data Provider for SqlServer" 
     type="System.Data.SqlClient.SqlClientFactory, System.Data, 
     Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    />
  </DbProviderFactories>
</system.data>

Retrieving Provider Information

You can retrieve information about all of the data providers installed on the local computer by using the GetFactoryClasses method. It returns a DataTable named DbProviderFactories that contains the columns described in the following table.

Column ordinal Column name Example output Description

0

Name

SqlClient Data Provider

Readable name for the data provider

1

Description

.Net Framework Data Provider for SqlServer

Readable description of the data provider

2

InvariantName

System.Data.SqlClient

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

3

AssemblyQualifiedName

System.Data.SqlClient.SqlClientFactory, 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

This DataTable can be used to enable a user to select a DataRow at run time. The selected DataRow can then be passed to the GetFactory method to create a strongly typed DbProviderFactory. For more information on creating factories, see Working with Factories.

GetFactoryClasses Example

This example demonstrates how to use the GetFactoryClasses method to return a DataTable containing information about the installed providers. The code iterates through each row in the DataTable, displaying information for each installed provider in the console window.

' This example assumes a reference to System.Data.Common.
Private Shared Function GetProviderFactoryClasses() As DataTable

    ' Retrieve the installed providers and factories.
    Dim table As DataTable = DbProviderFactories.GetFactoryClasses()

    ' Display each row and column value.
    Dim row As DataRow
    Dim column As DataColumn
    For Each row In table.Rows
        For Each column In table.Columns
            Console.WriteLine(row(column))
        Next
    Next

    Return table
End Function

See Also

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.