DbProviderFactory with Npgsql?
Asked Answered
V

5

22

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?

Veronikaveronike answered 2/8, 2010 at 4:22 Comment(0)
N
9

Have you read section 3.4 "Using Npgsql with ProviderFactory" from the fine manual?

Natatorial answered 2/8, 2010 at 10:10 Comment(3)
Actually I read it and adding it to machine.config didn't work. I checked and the version that comes with Mono for Arch Linux(2.0.0.0) didn't support it. I upgraded to the latest version and now everything is goodVeronikaveronike
This link is broken. Refer to ANeves's answer and step 4 of this article: codeproject.com/Articles/783552/…Fanestil
Actual link refers to github ;)Loverly
T
15

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

Townscape answered 8/11, 2013 at 19:28 Comment(1)
Up to date link for the official documentation: npgsql.org/doc/installation.htmlWhiffen
N
9

Have you read section 3.4 "Using Npgsql with ProviderFactory" from the fine manual?

Natatorial answered 2/8, 2010 at 10:10 Comment(3)
Actually I read it and adding it to machine.config didn't work. I checked and the version that comes with Mono for Arch Linux(2.0.0.0) didn't support it. I upgraded to the latest version and now everything is goodVeronikaveronike
This link is broken. Refer to ANeves's answer and step 4 of this article: codeproject.com/Articles/783552/…Fanestil
Actual link refers to github ;)Loverly
A
2

The type attribute value is important in the DbProviderFactories entry.

For me, the version number was incorrect. Correct version was :

<system.data>
  <DbProviderFactories>
    <add name="Npgsql Data Provider" 
         invariant="Npgsql" 
         support="FF" 
         description=".Net Framework Data Provider for Postgresql Server" 
         type="Npgsql.NpgsqlFactory, Npgsql, Version=2.2.3.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />
  </DbProviderFactories>
</system.data>

You can retrieve the value on your project with :

typeof(Npgsql.NpgsqlFactory).AssemblyQualifiedName
Airburst answered 11/1, 2015 at 13:42 Comment(0)
S
1

These were the steps that resolved it for me:

(1) add DbFactory provider to machine.config file located in the .NET Microsoft Frameworking folder

(2) register npgsql.dll and mono.security.dll in GAC using gacutil


Step by step details for:

(1) add DbFactory provider to machine.config

a. go to your relevant NET framework config directory (e.g. C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config)

b. edit the machine.config file and add the below line to DbProviderFactories

<DbProviderFactories>
    <add name="Npgsql Data Provider" 
         invariant="Npgsql" 
         support="FF" 
         description=".Net Framework Data Provider for Postgresql Server" 
         type="Npgsql.NpgsqlFactory, Npgsql"/>
  </DbProviderFactories>

(2) register npgsql.dll and mono.security.dll in GAC

a. check if npgsql and mono.security is in GAC folder (my GAC folder was located at C:\Windows\Microsoft.NET\assembly\GAC_MSIL)

If not, then use gacutil to install npgsql to GAC in command prompt using gacutil /i npgsql.dll

Sakhuja answered 28/12, 2015 at 12:54 Comment(0)
T
0

register ngsql and mono.security dll in GAC and add dbfactory provider in machine.config for both[32 & 64 bit version ]

Tammeratammi answered 7/11, 2013 at 15:9 Comment(1)
This answer could be more useful with some code examples to illustrate how to register assemblies in the GAC and how to modify machine.config, along with how to locate them.Resonate

© 2022 - 2024 — McMap. All rights reserved.