postgresql 如何添加可在 Visual Studio 中访问的自定义数据库提供程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4898476/
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:32:07  来源:igfitidea点击:

How to add custom DB provider to be accessible in Visual Studio?

visual-studiopostgresqlnpgsqldbproviderfactories

提问by Anton

I wanted to work with custom DB provider in Visual Studio. I need it to use Entity Framework.

我想在 Visual Studio 中使用自定义数据库提供程序。我需要它来使用实体框架。

For example, I downloaded NpgSQL, registered them in GAC:

比如我下载了NpgSQL,在GAC注册:

gacutil  -i  c:\temp\npgsql.dll
gacutil  -i  c:\temp\mono.security.dll

and added to machine.config file:

并添加到 machine.config 文件中:

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

But Npgsql did not appear in Datasource list in Visual Studio:

但是 Npgsql 没有出现在 Visual Studio 的数据源列表中:

Data source in VS

VS中的数据源

How to add custom DB provider to this list?

如何将自定义数据库提供程序添加到此列表中?

UPD: If I use command string edmgen.exe I got error:

UPD:如果我使用命令字符串 edmgen.exe 我得到错误:

error 7001: Failed to find or load the registered .Net Framework Data Provider.

错误 7001:无法找到或加载已注册的 .Net Framework 数据提供程序。

采纳答案by Anton

Old(from 7 Fabruary 2013): It is impossible to add Npgsql provider to be accesible in Visual Studio, because NpgSql for now does not support DDEX.

旧(来自 7 Fabruary 2013):在 Visual Studio 中添加 Npgsql 提供程序是不可能的,因为 NpgSql 现在不支持 DDEX。

Update on 29 of December 2013: It seems that DDEX support was added.

2013 年 12 月 29 日更新:似乎添加了 DDEX 支持。

回答by The Moof

You need to declare the DbFactoryProvider in a config file (Web.config, Machine.config, etc). Here's a sample one I pulled from a project using MySQL:

您需要在配置文件(Web.config、Machine.config 等)中声明 DbFactoryProvider。这是我从一个使用 MySQL 的项目中提取的示例:

<system.data>
  <DbProviderFactories>
    <remove invariant="MySql.Data.MySqlClient"/>
    <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.3.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
  </DbProviderFactories>
</system.data>

I also prefer declaring these in the application-level config files and have my apps use the local copy of the assembly. This helps with portability since we can't guarantee that the 3rd party provider is available in GAC.

我也更喜欢在应用程序级配置文件中声明这些,并让我的应用程序使用程序集的本地副本。这有助于可移植性,因为我们不能保证 GAC 中的第 3 方提供程序可用。

回答by xiaowing_sp

If you want to list up Npgsql in Datasource list in Visual Studio, this articlemay be a little helpful.

如果你想在 Visual Studio 的数据源列表中列出 Npgsql,这篇文章可能会有点帮助。

Anyway, since Visual Studio is delivered by Microsoft, obviously you need to work on the registry table.

无论如何,由于 Visual Studio 是由 Microsoft 提供的,显然您需要在注册表上工作。

回答by goingzhao

From: http://fxjr.blogspot.com/2011/05/npgsql-design-time-support-preview.html

来自:http: //fxjr.blogspot.com/2011/05/npgsql-design-time-support-preview.html

comes a very important step you have to make: Inside Npgsql.Designer2 folder, there is a file called NpgsqlProvider.gen.reg. You have to merge this file to your registry every time you start VS.Net to debug the project

您必须执行一个非常重要的步骤:在 Npgsql.Designer2 文件夹中,有一个名为 NpgsqlProvider.gen.reg 的文件。每次启动 VS.Net 调试项目时,都必须将此文件合并到注册表中