My project is .NET Framework 4.8 and end up in Exception while reading from stream with inner exception Von der Übertragungsverbindung können keine Daten gelesen werden: Eine vorhandene Verbindung wurde vom Remotehost geschlossen.
My test code
var connectionString = "server=localhost;port=5432;database=postgres;user id=postgres;password='postgres';";
using (var dataSource = NpgsqlDataSource.Create(connectionString))
{
using (var command = dataSource.CreateCommand("SELECT current_database() as db"))
{
using (var reader = command.ExecuteReader())
while (reader.Read())
{
Console.WriteLine($"Database: {reader["db"]}");
}
}
}
pg_hba.conf of windows postgres 15.7 server:
hostssl all all all cert clientname=CN
local all all scram-sha-256
host all all all scram-sha-256 # only required if not localhost
postgresql.conf requires ssl on:
ssl = on
ssl_cert_file = 'server.crt'
ssl_key_file = 'server.key'
ssl_ca_file = 'client_ca.crt'
it is als reproduceable without: ssl_cert_file, ssl_key_file, ssl_ca_file, then it will end up with a proper error message client certificates can only be checked if a root certificate store is available for .NET 8. .NET Framework 4.8 fails again.
Fun Fact:
If I build npgsql 8.0.8 in debug it works, if I build release it fails with above error.
- it happens only on the very first connect
- works with .NET 8