Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 本地Postgres的Npgsql连接字符串_C#_.net_Postgresql_Npgsql - Fatal编程技术网

C# 本地Postgres的Npgsql连接字符串

C# 本地Postgres的Npgsql连接字符串,c#,.net,postgresql,npgsql,C#,.net,Postgresql,Npgsql,下午好 我无法连接到Postgres数据库 我正在使用的应用程序必须在.NET 4上运行。我使用的是Npgsql,因为我仅限于.NET4,所以我使用的是Npgsql版本2.2.7(我相信3+需要.NET4.5) 应用程序将与Postgres在同一台计算机上运行。数据库是由第三方安装和设置的,因此我无法更改pg_hba.conf文件 我第一次尝试连接字符串如下所示: Server=localhost;Database=xyz;Integrated Security=true; host all

下午好

我无法连接到Postgres数据库

我正在使用的应用程序必须在.NET 4上运行。我使用的是Npgsql,因为我仅限于.NET4,所以我使用的是Npgsql版本2.2.7(我相信3+需要.NET4.5)

应用程序将与Postgres在同一台计算机上运行。数据库是由第三方安装和设置的,因此我无法更改pg_hba.conf文件

我第一次尝试连接字符串如下所示:

Server=localhost;Database=xyz;Integrated Security=true;
host all postgres 127.0.0.1/32  trust
host all xyz      127.0.0.1/32  trust
host all xyz      ::1/128       trust
host all postgres ::1/128       trust
但我有一个错误:

FATAL: 28000: no pg_hba.conf entry for host "::1", user "SYSTEM", database "xyz", SSL off
研究了该错误,并尝试了连接字符串的许多其他变体来修复该错误,包括:

Server=127.0.0.1;Database=xyz;Integrated Security=true;
Server=-h 127.0.0.1;Database=xyz;Integrated Security=true;
Server=127.0.0.1/32;Database=xyz;Integrated Security=true;
Server=::1;Database=xyz;Integrated Security=true;
Server=::1/128;Database=xyz;Integrated Security=true;
但什么都不管用。我要么得到

FATAL: 28000 ...
错误,还是简单的错误

Failed to establish a connection to ...
pg_hba.conf文件如下所示:

Server=localhost;Database=xyz;Integrated Security=true;
host all postgres 127.0.0.1/32  trust
host all xyz      127.0.0.1/32  trust
host all xyz      ::1/128       trust
host all postgres ::1/128       trust
这一切都在Windows 7计算机上运行,并且网络连接上的IPv6已关闭

可能很简单,但我能做什么?我无法更改pg_hba.conf文件,因此如何调整连接字符串才能正常工作?

请尝试以下操作: “服务器=[您的服务器];端口=[您的端口];数据库=[您的数据库];用户ID=[您的用户];密码=[您的密码];”

例如:
“Server=localhost;Port=5432;Database=BookStore;User ID=operator;Password=1234;”

pg_hba.conf
文件的开头添加(条目的顺序很重要!):

如果您不希望用户使用任何密码连接。 (有关更多信息,请查看:
(身份验证方法->sspi)

Secound选项是添加到您的连接字符串中,如@Cecilia Fernández所说。 但是,您需要在
pg_hba.conf
文件中添加以下内容:

  # Type    database      users      auth.method
  local     xyz           all        md5

不确定这是否是缺少密钥端口时的默认值,但我会尝试添加Server=127.0.0.1;端口=5432;谢谢你的建议,但没有效果。仍然收到相同的错误。Postgre不支持Port关键字