Npgsql problem in c # application - existing connection was forcibly closed by remote host

I get the following error when trying to open my Postgresql database using C # utility:

System.IO.IOException: cannot read data from transport connection: existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: existing connection was forcibly closed by the remote host

I tried to run this program from a remote computer and from the computer running the Postgresql server.

There are currently no firewalls on any computer, and I can connect to the database and server simply through the postgres admin utility using the same password. I checked that the username has permissions for the database.

Here is my connection code:

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.

+5
source share
1 answer

I spent 1 hour searching and did not find any problems. But then I realized that PG places its logs in the pg_log folder. I looked through it to see a possible problem.

It looks like you just need to have the correct host entry in the pg_hba.conf file. For me, this file is located in the C: \ Program Files \ PostgreSQL \ 9.1 \ data directory. for instance

host all all 192.168.1.2/32 md5

Where 192.168.1.2 is your client IP address.

By the way, you still need to open port 5432, usually Inboud (Windows Vista, Windows 7, Windows 2008 +).

+11
source

All Articles