- SQL Server
SQL Server: The certificate chain was issued by an authority that is not trusted
Also seen in: SSMS, Microsoft.Data.SqlClient, ODBC Driver 18, OLE DB Driver 19, JDBC, sqlcmd, PHP, pyodbc
In one sentence
The client asked for encryption and SQL Server presented a certificate no trust store vouches for, usually its own self-generated one; give the instance a CA-issued certificate instead.
Where you see it
SQL Server Management Studio (SSMS) and Microsoft.Data.SqlClient print:
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.) (Microsoft SQL Server, Error: -2146893019)
TCP worked, so host and port are right; the failure came during login, when the driver ran the TLS handshake and checked the server’s certificate. ODBC on Linux and macOS validates through OpenSSL and prints its wording (self signed certificate, hyphenated by newer OpenSSL, for SQL Server’s own certificate):
SSL routines::certificate verify failed: unable to get local issuer certificate
The JDBC driver wraps Java’s message:
"encrypt" property is set to "true" and "trustServerCertificate" property is set to "false" but the driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption: Error: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target.
Each client validates with a different library and trust store:
| Client | Validates with | Trust store |
|---|---|---|
| SSMS, SqlClient, OLE DB and ODBC on Windows, sqlcmd | Schannel (“SSL Provider”) | The computer’s Trusted Root Certification Authorities store |
| ODBC on Linux and macOS, with PHP, pyodbc and mssql-python | OpenSSL | /etc/ssl/certs on Debian, Ubuntu and SUSE; /etc/pki/tls/cert.pem on Red Hat |
| JDBC | Java | The JVM’s cacerts file or its trustStore property |
What it means
SQL Server always has a certificate: with none installed, the service generates a self-signed certificate at start-up and logs “A self-generated certificate was successfully loaded for encryption.” Its issuer is itself, so no trust store holds a certificate authority that vouches for it. Harmless, until every Microsoft driver changed its default:
- Microsoft.Data.SqlClient 4.0.0 changed the Encrypt default from false to true.
- Microsoft JDBC Driver 10.2.0 enabled TLS encryption by default (encrypt=true).
- ODBC Driver for SQL Server 18.0 changed the Encrypt default to yes, also written Mandatory, whereas ODBC Driver 17 defaults Encrypt to no, unless Authentication or an access token is set.
- OLE DB Driver for SQL Server 19.0 turned encryption on by default, with Encrypt=Mandatory.
- SSMS 20.0 set Encryption to Mandatory by default and left Trust server certificate unchecked.
- sqlcmd: the sqlcmd that ships with SQL Server 2025 (17.x) defaults -N to mandatory, while earlier versions default to optional.
- PHP’s sqlsrv and PDO_SQLSRV docs list a default of false for both Encrypt and TrustServerCertificate; the ODBC driver underneath does the TLS work.
With encryption on, the driver validates the certificate chain up to a root in its trust store, and the self-generated certificate fails. A client upgrade alone triggers it.
Likely causes
Still using the self-generated certificate
SQL Server logs event 26018 for the fallback, 26013 with a thumbprint for a configured certificate, and 26014 when it could not load that certificate:
Get-WinEvent -FilterHashtable @{LogName='Application'; ProviderName='MSSQLSERVER'; Id=26013,26014,26018} -MaxEvents 3 | Format-List TimeCreated, Message
Message : A self-generated certificate was successfully loaded for encryption.
For a named instance the provider is MSSQL$INSTANCENAME; on Linux read /var/opt/mssql/log/errorlog. openssl s_client on port 1433 shows nothing: before TDS 8.0 the handshake is wrapped in TDS pre-login packets.
Fix: get a certificate from a CA your clients trust, usually the domain’s internal CA: the FQDN in the Common Name, every name clients type in the Subject Alternative Name (short name, aliases, listener names), Server Authentication in Enhanced Key Usage, and a legacy CSP such as Microsoft RSA SChannel Cryptographic Provider, since SQL Server cannot use Key Storage Provider keys (create the CSR on Windows).
Import it in SQL Server Configuration Manager, which has had integrated certificate management since SQL Server 2019 (15.x), and that version of the tool also works with older instances: Protocols for your instance, Properties, Certificate tab. The wizard accepts only a subject matching the host name; for any other, import through the Certificates MMC, give the service account Read under Manage Private Keys (or the service can fail to restart), pick it from the dropdown and restart.
Availability groups need every replica’s names and the listener names in the SAN; importing on the primary deploys to every replica. A named instance’s SAN still holds host names: the part after the backslash is not a DNS name.
On Linux, mssql-conf takes a PEM certificate and key owned by mssql (convert a PFX first if needed):
sudo chown mssql:mssql /etc/ssl/certs/mssql.pem /etc/ssl/private/mssql.key
sudo chmod 600 /etc/ssl/certs/mssql.pem /etc/ssl/private/mssql.key
sudo /opt/mssql/bin/mssql-conf set network.tlscert /etc/ssl/certs/mssql.pem
sudo /opt/mssql/bin/mssql-conf set network.tlskey /etc/ssl/private/mssql.key
sudo systemctl restart mssql-server
A private CA this client does not trust
Other clients connect and event 26013 names a thumbprint: this client’s store lacks the issuing root. On Windows, Schannel logs each rejection as System event 36882 with the server’s certificate attached: read the issuer there.
Fix: add that root: Windows for the Schannel clients, Linux for ODBC and the drivers on it, the Java cacerts file for JDBC. Add the root, never the leaf certificate and never the fallback.
Installed, but not loaded
The log still shows 26018, or shows 26014. Check the certificate:
certutil -v -store My "<thumbprint>"
Look for KeySpec = 1 -- AT_KEYEXCHANGE, Server Authentication (1.3.6.1.5.5.7.3.1) and the DNS names. KeySpec = 2 or 0 means reissue with a legacy CSP; otherwise give the service account Read on the private key and restart.
The name is not in the certificate
“The target principal name is incorrect” means the chain was trusted but the certificate lacks the name you connected to: an alias, short name, listener name or IP address.
Fix: reissue with every name clients use. HostNameInCertificate (SqlClient, where it and Encrypt=Strict arrived in 5.0; ODBC spells it HostnameInCertificate) names the SAN entry to expect; it does not repair a missing root.
Check yours
Paste the certificate the instance presents (export it from the Certificates MMC without the private key, or use the PEM you gave mssql-conf) to check the issuer and the SAN list.
Learn why
- Who do we trust? CAs, trust stores and self-signed certificates
- Names and jobs: SANs, wildcards, key usage and the CA flag
- Related: .NET: the remote certificate is invalid and Java: PKIX path building failed.
- Microsoft: Certificate chain not trusted, Encrypt connections, Certificate requirements, Encrypt connections on Linux and SqlClient encryption.
Does your team keep hitting this?
Everyone can use the lessons. Team seats add earned credentials, invitations and a completion report, so you see who has finished.
Early edition. Written with AI assistance and checked against primary sources; an independent expert review is planned. Found a mistake? Tell us.