Custom .NET Data Providers

Can I use a custom .NET data provider without installing it in the GAC?

Is it possible to reference a custom DLL and register it inside my configuration file?

+8
dataprovider
source share
1 answer

Yes , you can register the implementation of the DbProviderFactory class by adding the following section in the configuration file:

<system.data> <DbProviderFactories> <add name="My Custom Data Provider" invariant="MyCustomDataProvider" description="Data Provider for My Custom Store" type="MyNamespace.MyCustomProviderFactory, MyCustomDataProvider, Version=1.0.0.0, Culture=neutral, PublicKeyToken=" /> </DbProviderFactories> </system.data> 

The MyCustomDataProvider assembly MyCustomDataProvider not have to be registered in the GAC, but can be deployed with the application as a private assembly .

You can contact the registered data provider programmatically using the value specified in the invariant attribute. For example, you could tell ADO.NET to use MyNamespace.MyCustomProviderFactory , specifying MyCustomProvider as providerName in the connection string:

 <connectionStrings> <add name="ConnString" providerName="MyCustomProvider" connectionString="MyCustomConnectionString" /> </connectionStrings> 

In code, you can use the same provider name using the DbProviderFactories.GetFactory method:

 DbProviderFactory factory = DbProviderFactories.GetFactory("MyCustomDataProvider"); 

where factory will be an instance of the MyNamespace.MyCustomProviderFactory class.

+6
source share

All Articles