繁体   English   中英

本地Postgres的Npgsql连接字符串

[英]Npgsql connection string for local Postgres

下午好。

我无法连接到Postgres数据库。

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

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

我在连接字符串上的第一个刺刺如下所示:

Server=localhost;Database=xyz;Integrated Security=true;

但是我得到了这个错误:

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文件如下所示:

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 = [您的用户];密码= [您的密码];”

例如:“服务器=本地主机;端口= 5432;数据库= BookStore;用户ID =操作员;密码= 1234;”

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

  # Type    database      users      auth.method
  local     xyz           all        sspi

如果您不希望用户使用任何密码进行连接。 (有关更多信息,请检查: https : //www.postgresql.org/docs/9.1/static/auth-methods.html#SSPI-AUTH https://www.postgresql.org/docs/9.1/static/auth-pg -hba-conf.html (auth-method -> sspi) -method- (auth-method -> sspi)

正如@CeciliaFernández所说,Secound选项已添加到您的ConnectionString中。 但是然后您需要添加到pg_hba.conf文件中:

  # Type    database      users      auth.method
  local     xyz           all        md5

暂无
暂无

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

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