DbProviderFactory with Npgsql?

Earlz picture Earlz · Aug 2, 2010 · Viewed 15.3k times · Source

I have a project which I'm trying to port from SQL Server to PostgreSQL. I've got almost everything done I believe except for I can not get DbProviderFactory to work with Npgsql.

Factory = DbProviderFactories.GetFactory("Npgsql");

yields

Unhandled Exception: System.Configuration.ConfigurationErrorsException: Failed to find or load the registered .Net Framework Data Provider.

How do I fix this?

Answer

ANeves picture ANeves · Nov 8, 2013

Try defining a factory in your app.config:

<system.data>
  <DbProviderFactories>
    <add name="Npgsql Data Provider" invariant="Npgsql"
         description="Data Provider for PostgreSQL"
         type="Npgsql.NpgsqlFactory, Npgsql" />
  </DbProviderFactories>
</system.data>

Via http://fxjr.blogspot.pt/2013/06/npgsql-code-first-entity-framework-431.html