I need to have DbProviderFactories.GetFactory() return the provider for Sqlite. However, I have Sqlite added to my project via NuGet and want to avoid having to put it in the GAC and update machine.config. One of the advantages of Sqlite is it is there with no configuration.
However, I have a number of libraries that pull the connector from GetFactory().
Is there a way to do this?
thanks - dave
You just have to add an app.config file to your project, with the invariant that you want to add.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite"></remove>
<add name="ADO.NET Provider for SQLite"
invariant="System.Data.SQLite"
description="ADO.NET Provider for SQLite "
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite">
</add>
</DbProviderFactories>
</system.data>
</configuration>
The type attribute contains the namespace of the provider factory and the namespace of the provider itself.
The GetFactory
method first looks in your local app.config file, then in your machine.config. Just make sure that you do have a reference to the SQLite assembly, as you do.