开发者

DbProviderFactory with Npgsql?

开发者 https://www.devze.com 2023-01-10 00:36 出处:网络
I have a project which I\'m trying to port from SQL Server to PostgreSQL. I\'ve got almost everything done I beli开发者_C百科eve except for I can not get DbProviderFactory to work with Npgsql.

I have a project which I'm trying to port from SQL Server to PostgreSQL. I've got almost everything done I beli开发者_C百科eve 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?


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


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


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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号