postgresql 使用 Npgsql 的 DbProviderFactory?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3384966/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-20 00:14:04  来源:igfitidea点击:

DbProviderFactory with Npgsql?

.netpostgresqlmonodbproviderfactories

提问by Earlz

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 DbProviderFactoryto work with Npgsql.

我有一个项目,我试图将其从 SQL Server 移植到 PostgreSQL。我已经完成了我相信的几乎所有事情,除了我无法DbProviderFactory使用 Npgsql。

Factory = DbProviderFactories.GetFactory("Npgsql");

yields

产量

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

未处理的异常:System.Configuration.ConfigurationErrorsException:无法找到或加载已注册的 .Net Framework 数据提供程序。

How do I fix this?

我该如何解决?

采纳答案by Milen A. Radev

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

您是否阅读过精美手册中的第 3.4 节“在 ProviderFactory 中使用 Npgsql” ?

回答by ANeves

Try defining a factory in your app.config:

尝试在你的 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

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

回答by Dude Pascalou

The typeattribute value is important in the DbProviderFactoriesentry.

类型的属性值是重要DbProviderFactories条目。

For me, the version numberwas 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

回答by Programming with Mark

These were the steps that resolved it for me:

这些是为我解决问题的步骤:

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

(1) 将 DbFactory 提供程序添加到位于 .NET Microsoft Frameworking 文件夹中的 machine.config 文件

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

(2)使用gacutil在GAC中注册npgsql.dll和mono.security.dll



Step by step details for:

分步详细信息:

(1) add DbFactory provider to machine.config

(1) 将 DbFactory 提供程序添加到 machine.config

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

一种。转到您相关的 NET 框架配置目录(例如 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config)

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

湾 编辑 machine.config 文件并将以下行添加到 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

(2)在GAC中注册npgsql.dll和mono.security.dll

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

一种。检查 npgsql 和 mono.security 是否在 GAC 文件夹中(我的 GAC 文件夹位于 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

如果没有,则使用 gacutil 在命令提示符下使用 gacutil /i npgsql.dll 将 npgsql 安装到 GAC

回答by user2965379

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

在 GAC 中注册 ngsql 和 mono.security dll 并在 machine.config 中为两者添加 dbfactory 提供程序 [32 和 64 位版本]