Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: "Couldn't set ssl mode"

Tags:

npgsql

I'm trying to set the SSL Mode in my connection string:

SSL Mode=preferred;

But I'm getting an ArgumentException when my code tries to connect to the database:

Exception info showing an ArgumentException with message "Couldn't set ssl mode. Parameter name: ssl mode". InnerException message is "Requested value 'preferred' was not found.".

Notice that the InnerException, says:

Requested value 'preferred' was not found.

Looking at the following documentation, it should be valid to specify required, disabled or preferred:

  • Npgsql Connection String Parameters
  • Npgsql Security and Encryption

I'm using Npgsql 3.0.3, which I obtained using NuGet:

NuGet showing Npgsql 3.0.3 installed

like image 785
Sam Avatar asked Oct 17 '25 09:10

Sam


2 Answers

So it turns out that you actually need to specify verb values rather than adjectives:

  • Disable
  • Prefer
  • Require

For example:

SSL Mode=Prefer;

Edit: the documentation has since been corrected.

like image 159
Sam Avatar answered Oct 19 '25 12:10

Sam


Add sslmode=Require; and Trust Server Certificate=true; as it is in your connection string.It will work for sure.

like image 42
Chandra Vijay Vishwakarma Avatar answered Oct 19 '25 12:10

Chandra Vijay Vishwakarma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!