I am attempting to connect to a postgresql database which uses SSL via my c# application. But I'm unable to work out what the correct connection string would be. Is anyone able to help?
NpgsqlConnection postgresConn;
public PostgreManager()
{
openConnection();
}
private void openConnection()
{
postgresConn = new NpgsqlConnection("Server=10.153.8.4;Port=5432;Database=au_wa_jpc;User Id=readonly;Password=myPass;");
postgresConn.Open();
}
Edit:
I have attempted to use Ssl Mode=Require;
in the connection string, however it throws the following exception.
An unhandled exception of type 'System.IO.IOException' occurred in Npgsql.dll
Additional information: TlsClientStream.ClientAlertException: CertificateUnknown: Server certificate was not accepted. Chain status: A certificate chain processed, but terminated in a root certificate which is not trusted by the trust provider.
. The specified hostname was not present in the certificate.
With SSL support compiled in, the PostgreSQL server can be started with SSL enabled by setting the parameter ssl to on in postgresql. conf. The server will listen for both normal and SSL connections on the same TCP port, and will negotiate with any connecting client on whether to use SSL .
SSL (Secured Sockets Layer) also known as TLS (Transport Layer Security) is a standard security technology for establishing encrypted connection between a server and a client.
Verify SSL is Enabled Verify the configuration file for Postgres has the ca file configured cat /db/postgresql/*/data/postgresql. conf | grep 'ssl' . If the configuration file shows SSL is on and the server indicated it was off you'll need to Restart PostgreSQL.
You can set the rds. force_ssl parameter to 1 (on) to require SSL for connections to your DB instance. To change the value of this parameter, you need to create a custom DB parameter group. You then change the value for rds.
As described in the documentation here and here, you'll have to use SSL Mode=Require;Trust Server Certificate=true
in your connection string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With