<!-- https://pkizerotohero.com/errors/sql-server-certificate-chain-not-trusted/ | Markdown mirror of the HTML page | PKI Zero to Hero, by Duyutech BV -->

> Every Microsoft SQL Server driver now encrypts by default and rejects the instance's self-generated certificate. Find what it loads and fix it.

Source: https://pkizerotohero.com/errors/sql-server-certificate-chain-not-trusted/ · Last reviewed: 2026-10-24

- 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.

[Check yours: Certificate decoder](https://pkizerotohero.com/tools/decoder/)

## Where you see it

SQL Server Management Studio (SSMS) and Microsoft.Data.SqlClient print:

```text
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](https://pkizerotohero.com/handbook/glossary/#tls-handshake) and checked the server’s [certificate](https://pkizerotohero.com/handbook/glossary/#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):

```text
SSL routines::certificate verify failed: unable to get local issuer certificate
```

The JDBC driver wraps Java’s message:

```text
"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](https://pkizerotohero.com/handbook/glossary/#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](https://pkizerotohero.com/handbook/glossary/#self-signed-certificate) at start-up and logs “A self-generated certificate was successfully loaded for encryption.” Its [issuer](https://pkizerotohero.com/handbook/glossary/#issuer) is itself, so no trust store holds a [certificate authority](https://pkizerotohero.com/handbook/glossary/#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](https://pkizerotohero.com/handbook/glossary/#certificate-chain) up to a [root](https://pkizerotohero.com/handbook/glossary/#root-certificate) 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:

```powershell
Get-WinEvent -FilterHashtable @{LogName='Application'; ProviderName='MSSQLSERVER'; Id=26013,26014,26018} -MaxEvents 3 | Format-List TimeCreated, Message
```

```text
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](https://pkizerotohero.com/handbook/glossary/#private-ca): the FQDN in the Common Name, every name clients type in the [Subject Alternative Name](https://pkizerotohero.com/handbook/glossary/#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](https://pkizerotohero.com/guides/create-csr-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](https://pkizerotohero.com/guides/convert-pfx-pem/) first if needed):

```bash
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](https://pkizerotohero.com/guides/add-root-ca-windows/) for the Schannel clients, [Linux](https://pkizerotohero.com/guides/add-root-ca-linux/) for ODBC and the drivers on it, the [Java cacerts file](https://pkizerotohero.com/guides/add-root-ca-java/) for JDBC. Add the root, never the [leaf certificate](https://pkizerotohero.com/handbook/glossary/#leaf-certificate) and never the fallback.

### Installed, but not loaded

The log still shows 26018, or shows 26014. Check the certificate:

```powershell
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](https://pkizerotohero.com/handbook/glossary/#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.

Warning

TrustServerCertificate is not a fix

The line everyone pastes is `TrustServerCertificate=True` (`=yes` in ODBC and OLE DB, `trustServerCertificate=true` in JDBC, `-C` in sqlcmd, the SSMS checkbox). The connection stays encrypted, but nothing proves which server you reached: any machine answering on port 1433 with any certificate receives your login and your data. That is a [man-in-the-middle](https://pkizerotohero.com/handbook/glossary/#man-in-the-middle). `Encrypt=Optional` is worse: unless the server forces encryption, queries travel in clear. Microsoft calls the bypass temporary, and strict mode refuses it: strict encryption and TDS 8.0 arrived with SQL Server 2022 (16.x), and under Strict the driver always validates the certificate (JDBC’s `encrypt=strict` arrived in 11.2.0). Keep it to throwaway development containers.

## Check yours

*Interactive tool: Certificate decoder (runs in the browser at [/tools/decoder/](https://pkizerotohero.com/tools/decoder/))*

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](https://pkizerotohero.com/handbook/trust-stores/)
- [Names and jobs: SANs, wildcards, key usage and the CA flag](https://pkizerotohero.com/handbook/names-and-key-usage/)
- Related: [.NET: the remote certificate is invalid](https://pkizerotohero.com/errors/dotnet-remote-certificate-invalid/) and [Java: PKIX path building failed](https://pkizerotohero.com/errors/java-pkix-path-building-failed/).
- Microsoft: [Certificate chain not trusted](https://learn.microsoft.com/en-us/troubleshoot/sql/database-engine/connect/certificate-chain-not-trusted), [Encrypt connections](https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/configure-sql-server-encryption), [Certificate requirements](https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/certificate-requirements), [Encrypt connections on Linux](https://learn.microsoft.com/en-us/sql/linux/security/encrypted-connections) and [SqlClient encryption](https://learn.microsoft.com/en-us/sql/connect/ado-net/encryption-and-certificate-validation).

**Early edition.** Written with AI assistance and checked against primary sources; an independent expert review is planned. Found a mistake? [Tell us](https://pkizerotohero.com/contact/?topic=content-error&page=/errors/sql-server-certificate-chain-not-trusted/).

Last reviewed 24 October 2026Edition 0.9

## Learn why it happens

- [Chapter 12: Who do we trust? CAs, trust stores and self-signed certificates](https://pkizerotohero.com/handbook/trust-stores/)
- [Chapter 9: Names and jobs: SANs, wildcards, key usage and the CA flag](https://pkizerotohero.com/handbook/names-and-key-usage/)

## Everything on this topic

- [Chains and trust stores](https://pkizerotohero.com/topics/chains-and-trust/)
