简体   繁体   English

连接字符串上的Npgsql异常

[英]Npgsql exception on connection string

I cant get Npgsql connection string to work. 我无法使Npgsql连接字符串正常工作。 I've tried some ways, for example 我尝试了一些方法,例如

NpgsqlConnection conn = new NpgsqlConnection("Server=192.168.1.220;User Id=pgsql;Password=pgsql;Database=pgsql;");

or 要么

var conn = new NpgsqlConnection("Host=192.168.1.220;Username=pgsql;Password=pgsql;Database=pgsql");

both throws me exception: 两者都抛出异常:

The type initializer for 'Npgsql.NpgsqlConnectionStringBuilder' threw an exception. “ Npgsql.NpgsqlConnectionStringBuilder”的类型初始值设定项引发了异常。

Im running Windows XP 64bit with VS 2010. I've already tried to connect from that machine to my pgsql server using ODBC or pgAdmin III - both works ok. 我在VS 2010上运行Windows XP 64位。我已经尝试使用ODBC或pgAdmin III从该计算机连接到我的pgsql服务器-都可以。

Could be this problem related to my Npgsql installation? 这个问题可能与我的Npgsql安装有关吗? I was not able to install it with NuGet, because I got following error: 我无法使用NuGet进行安装,因为出现以下错误:

PM> Install-Package Npgsql Installing 'Npgsql 3.2.1'. PM>安装包Npgsql正在安装“ Npgsql 3.2.1”。 Successfully installed 'Npgsql 3.2.1'. 已成功安装“ Npgsql 3.2.1”。 Adding 'Npgsql 3.2.1' to Project. 在项目中添加“ Npgsql 3.2.1”。 Uninstalling 'Npgsql 3.2.1'. 卸载“ Npgsql 3.2.1”。 Successfully uninstalled 'Npgsql 3.2.1'. 已成功卸载“ Npgsql 3.2.1”。 Install failed. 安装失败。 Rolling back... Install-Package : Could not install package 'Npgsql 3.2.1'. 正在回滚... Install-Package:无法安装软件包“ Npgsql 3.2.1”。 You are trying to install this package into a project that targets '.NETFramework,Version=v4.0,Profile=Client', but the packag e does not contain any assembly references or content files that are compatible with that framework. 您正在尝试将此程序包安装到以'.NETFramework,Version = v4.0,Profile = Client'为目标的项目中,但是该程序包不包含任何与该框架兼容的程序集引用或内容文件。 For more information, contact the package author. 有关更多信息,请与软件包作者联系。 At line:1 char:16 + Install-Package <<<< Npgsql + CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand 第1行:16个字符:16 + Install-Package <<<< Npgsql + CategoryInfo:未指定:(:) [Install-Package],InvalidOperationException + FullyQualifiedErrorId:NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand

I've tried also to switch target framework to 4.0 or 3.5, but result was exactly the same. 我也尝试过将目标框架切换到4.0或3.5,但结果完全一样。 So I installed Npgsql simply by extracting .dll from MSI installation, then load it as reference. 因此,我仅通过从MSI安装中提取.dll来安装Npgsql,然后将其加载为参考。

Does anyone know how to make connection string to work? 有谁知道如何使连接字符串工作?

You forgot about the port. 您忘记了港口。 Maybe this is the cause. 也许这就是原因。 The standard PostgreSQL server listening on port 5432. 在端口5432上侦听的标准PostgreSQL服务器。

NpgsqlConnection conn = new NpgsqlConnection("Server=192.168.1.220;Port=5432;User Id=pgsql;Password=pgsql;Database=pgsql;");

Example Connection String 示例连接字符串

Maybe you haven't a library Mono.Security.dll . 也许您没有Mono.Security.dll库。 It is necessary in the older version less then 3.0 or is enabled the system firewall? 在低于3.0的旧版本中是必需的,还是启用了系统防火墙?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM