Published: February 15 2023

SqlClient.SqlException - The certificate chain was issued by an authority that is not trusted

I got the following error the other day when connecting to a local SQL server database from ASP.NET Core:

Unhandled exception. Microsoft.Data.SqlClient.SqlException (0x80131904):
A connection was successfully established with the server, but then an error occurred during the login process.
(provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)


Cause of the SSL error

The reason for the error is that SQL Server uses a self-signed SSL certificate to encrypt the connection to the database which is not trusted by default by the ASP.NET Core client.

This is the connection string that was getting the error:

"Server=localhost; Database=my-database; User Id=test; Password=pass123;"

How to fix the SSL error

To fix the error I configured ASP.NET Core to trust the server certificate by adding TrustServerCertificate=true to the connection string.

This is the connection string that fixed the SSL error:

"Server=localhost; Database=my-database; User Id=test; Password=pass123; TrustServerCertificate=true;"


Need Some .NET Help?

Search fiverr for freelance .NET developers.

Follow me for updates

On Twitter or RSS.

When I'm not coding...

Me and Tina are on a motorcycle adventure around Australia.
Come along for the ride!


Supported by