Microsoft SQL Server - The remote certificate was rejected by the provided RemoteCertificateValidationCallback

In a real-world scenario, don’t use the SA user to connect to the database from an application, and don’t put passwords into your code or config files.

While working on another blog post I hit this exception when connecting to a SQL Server running in Docker -

The remote certificate was rejected by the provided RemoteCertificateValidationCallback.
Remote Certificate Validation Callback
Remote Certificate Validation Callback

My connection string that caused the error was -

Server=localhost;Database=SalesDb;User Id=SA;Password=A!VeryComplex123Password;MultipleActiveResultSets=true

And the fix is to add TrustServerCertificate=True to the connection string -

Server=localhost;Database=SalesDb;User Id=SA;Password=A!VeryComplex123Password;MultipleActiveResultSets=true;TrustServerCertificate=True

comments powered by Disqus

Related