关于 postgresql:npgsql 在 c# app 中的问题 – 一个现有的连接被远程主机强行关闭 | 珊瑚贝

npgsql trouble in c# app – An existing connection was forcibly closed by the remote host


尝试从 C# 实用程序打开我的 Postgresql 数据库时出现以下错误:

System.IO.IOException: Unable to read data from the transport
connection: An existing connection was forcibly closed by the remote
host. —> System.Net.Sockets.SocketException: An existing connection
was forcibly closed by the remote host

我已尝试从远程计算机和运行 Postgresql 服务器的计算机上运行此程序。

此时两台计算机上都没有防火墙,我可以使用相同的密码通过 postgres 管理实用程序很好地连接到数据库和服务器。我已检查用户名是否具有数据库权限。

这是我的连接代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
public bool updateFromServer()
{
    try
    {
        NpgsqlConnection conn = new NpgsqlConnection(connString);
        conn.Open();
        conn.Close();
        return true;
    }
    catch (Exception e)
    {
        conn.close()
        return false;
    }
}

对此的任何帮助将不胜感激。

  • 服务器日志是显而易见的地方。另外,我不是 C# 程序员,但你没有得到堆栈跟踪吗?哪一行代码导致了异常?


我花了 1 个小时搜索相同的内容,但没有发现任何问题。但后来意识到 PG 将其日志放在 pg_log 文件夹中。我查看了它以查看可能的问题。

事实证明,您只需要在 “pg_hba.conf” 文件中有正确的 “host” 条目。对我来说,这个文件位于 C:\\\\\\\\Program Files\\\\\\\\PostgreSQL\\\\\\\\9.1\\\\\\\\data 目录中。
例如

host all all 192.168.1.2/32 md5

其中 192.168.1.2 – 是您客户端的 IP 地址。

顺便说一句,您仍然需要将 5432 端口作为入站规则打开(Win??dows Vista、Windows 7、Windows 2008)。

  • 非常感谢,这真的是一个救生员。


来源:https://www.codenong.com/10426617/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_10006.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?