Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Servers, nginx and Docker

A .NET app on Linux cannot trust the SQL Server certificate

ErrorSSL Provider: The certificate chain was issued by an authority that is not trusted.

Short answer

Microsoft.Data.SqlClient 4.0 and later encrypts by default and validates the server certificate. A Linux host or container does not trust a private or self-signed CA, so the login fails. Install the CA on the client, pin the certificate, or fix the name. TrustServerCertificate=true is for isolated development only.

  • Applies to Microsoft.Data.SqlClient 5.x, .NET 8, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Confirm the connection string. If Encrypt is not set, SqlClient 4.0 and later uses Mandatory with certificate validation.

    grep -rn "Encrypt\|TrustServerCertificate" appsettings*.json
  2. 2Match what you see, then jump to its fix

    1. 1The error mentions an authority that is not trusted; the same code works on a Windows machine that trusts your CA.The issuing CA is not in the Linux trust storeFix
    2. 2Chain trust is fine but validation still fails when you connect through an alias or IP address.The name you connect with is not in the certificateFix
    3. 3The server uses its own generated certificate and the client is a locked-down container.A self-signed server certificate you cannot add to a trust storeFix

What does the error look like?

  • SSL Provider: The certificate chain was issued by an authority that is not trusted.

Cause 1 of 3

The issuing CA is not in the Linux trust store

1Check

An enterprise or self-made certificate is not automatically trusted inside a Linux container or on another computer. The CA and any intermediates must be trusted on every client host or container.

sudo ls /etc/ssl/certs/ | grep my-ca

2Fix

Install the CA certificate as a PEM file with the .crt extension, then update the trust store.

sudo apt-get install -y ca-certificates
sudo cp my-ca.crt /usr/local/share/ca-certificates
sudo update-ca-certificates

3Verify

The PEM file appears in /etc/ssl/certs. Restart the app and connect again with TrustServerCertificate=false.

sudo ls /etc/ssl/certs/ | grep my-ca

Confirmed by ubuntu.com

Did this fix it?

Cause 2 of 3

The name you connect with is not in the certificate

1Check

SqlClient compares the Server value with the certificate's subject alternative names.

grep -rn Server= appsettings*.json

2Fix

Connect with a name that is in the certificate, or reissue it with the alias. If you must keep the alias, set HostNameInCertificate (SqlClient 5.0 and later) to the name in the certificate.

Server=tcp:sql-alias.example.com,1433;Database=app;Encrypt=true;TrustServerCertificate=false;HostNameInCertificate=sql-server.example.com;

3Verify

Open a connection from the app again.

dotnet run

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 3

A self-signed server certificate you cannot add to a trust store

1Check

Export the server certificate from a channel you trust, not from the network connection that is failing.

ls -l /certs/sql-server.cer

2Fix

Pin it with the ServerCertificate keyword (SqlClient 5.1 and later), with Encrypt=Mandatory or Strict and TrustServerCertificate=false. Update the pin whenever the certificate is renewed.

Server=tcp:sql.example.com,1433;Database=app;Encrypt=Strict;TrustServerCertificate=false;ServerCertificate=/certs/sql-server.cer;

3Verify

A missing, unreadable or mismatched file fails the connection, so a successful open means the pin matched.

dotnet run

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Put the CA into your base image at build time so every container trusts it.
  • Do not ship TrustServerCertificate=true to production: it encrypts but does not verify the server.
  • Plan certificate renewal, and update any pin before the old certificate expires.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Servers

dotnet stops with 'the folder host/fxr does not exist' on Ubuntu

A fatal error occurred. The required library libhostfxr.so could not be found.

This error nearly always means .NET packages came from two different package feeds, usually Ubuntu's own and Microsoft's, and each put files in a different place.

3 causes, each with a fix

Servers

dnf cannot install MySQL on Amazon Linux 2023

dnf cannot find a mysql-server package on Amazon Linux 2023

Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.

3 causes, each with a fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.