在C#应用程序npgsql麻烦 - 一个现有的连接被强行关闭远程主机
我想从C#程序打开我的PostgreSQL数据库时,收到以下错误:
I am getting the following error when trying to open my Postgresql database from a C# utility:
System.IO.IOException:无法读取来自运输
连接数据:一个现有的连接被强行远程
主机关闭。 ---> System.Net.Sockets.SocketException:一个现有的连接
被强行关闭远程主机
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服务器正在运行的计算机此程序。
I have tried running this program from a remote computer and from the computer on which the Postgresql server is running.
有一台计算机上没有防火墙在这一刻,我能够使用相同的密码通过Postgres的管理实用工具连接到数据库和服务器就好了。我已经检查了用户名有权限的数据库。
There are no firewalls on either computer at this moment and I am able to connect to the database and server just fine through the postgres admin utility using the same password. I have checked that the username has permissions to the database.
下面是我的连接代码:
public bool updateFromServer()
{
try
{
NpgsqlConnection conn = new NpgsqlConnection(connString);
conn.Open();
conn.Close();
return true;
}
catch (Exception e)
{
conn.close()
return false;
}
}
任何帮助,将不胜感激。
Any help with this would be appreciated.
我已经花了100小时去找相同,没有发现问题。但后来意识到,PG把它的日志中pg_log文件夹中。我看着它,看看可能的问题。
I had spent 1 hour searching same and found no issues. But then realized that PG puts its logs in pg_log folder. I looked in it to see possible issue.
它变成你只需要在的pg_hba.conf文件正确的主机条目。对于我这个文件位于C:\Program Files\PostgreSQL\9.1\data目录。
为例
It turn out you just need to have correct "host" entry in "pg_hba.conf" file. For me this file is in C:\Program Files\PostgreSQL\9.1\data directory. For example
承载所有所有192.168.1.2/32 MD5
host all all 192.168.1.2/32 md5
在哪里192.168.1.2 - 是你的客户端的IP地址
Where 192.168.1.2 - is your client's ip address.
顺便说一句,你仍然需要有5432端口Inboud规则开放( Windows Vista中,Windows 7中的Windows 2008 +)。
BTW, you still need to have 5432 port open as Inboud rule (windows Vista, Windows 7, Windows 2008+).