SqlException: A connection was successfully established with the server, but then an error occurred during the login process. (The certificate chain was issued by an authority that is not trusted)
The SQL Server certificate is not trusted by the client, and Microsoft.Data.SqlClient 4+ encrypts by default.
Exact message you may see
The certificate chain was issued by an authority that is not trustedSqlException error occurred during the login process
Seen on:
.NET SQL Server
Meaning
Since SqlClient 4.0 Encrypt=true is the default. A self-signed server certificate (typical in dev and Docker) fails validation.
Common causes
- Self-signed SQL Server certificate
- Encrypt defaulting to true after a package upgrade
- Certificate CN does not match the host
- CA missing on the client
⚡ Quick fix
- Add
TrustServerCertificate=Truein dev only - Install a trusted certificate on the server
- Add the CA to the client trust store
Detailed fix by platform
Connection string
Server=db;Database=app;User Id=sa;Password=...;Encrypt=True;TrustServerCertificate=True
How to diagnose
- Version — SqlClient version?
- Cert — Self-signed?
- Env — Dev or prod?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Most viewed in .NET
- FileNotFoundException assembly Could not load file or assembly 'X, Version=…' or one of its dependencies
- Unable to cast object of type System.InvalidCastException: Unable to cast object of type 'X' to type 'Y'
- NullReferenceException System.NullReferenceException: Object reference not set to an instance of an object
Other ways to find it
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Did this fix work for you?
Report a correction or suggest an improvement
Last updated 2 Dec 2026