Search code examples
npgsql

Error: "Couldn't set ssl mode"


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:

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

NuGet showing Npgsql 3.0.3 installed


Solution

  • 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.