Encrypt SQL Server with TLS

SQL Server always encrypts the login, but the actual data only if a certificate is set up and client or server require it. Since ODBC Driver 18 and the new SqlClient versions, clients require it by default. Since then one particular error shows up very often.

The most common error

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

It appears as soon as a new driver (ODBC Driver 18, Microsoft.Data.SqlClient 4.0 and later, current SSMS) with encryption on by default meets a server that only has its self-generated certificate. The quick workaround TrustServerCertificate=True turns verification off and makes the connection vulnerable. The proper fix is a certificate the clients trust.

Certificate requirements

With certreq you get there with these lines in the INF file:

[NewRequest]
Subject = "CN=sql01.corp.local"
KeyLength = 2048
KeySpec = 1
MachineKeySet = TRUE
Exportable = TRUE
ProviderName = "Microsoft RSA SChannel Cryptographic Provider"
ProviderType = 12
RequestType = PKCS10
[EnhancedKeyUsageExtension]
OID = 1.3.6.1.5.5.7.3.1
[Extensions]
2.5.29.17 = "{text}"
_continue_ = "dns=sql01.corp.local&"
_continue_ = "dns=sql01"

Permissions for the service account

The SQL Server service account (e.g. NT Service\MSSQLSERVER) needs read access to the private key: certlm.msc → certificate → All Tasks → Manage Private Keys. Without it the service does not start after the assignment, and the error log says the certificate could not be loaded.

Assign the certificate and force encryption

  1. SQL Server Configuration Manager → SQL Server Network Configuration → Protocols for MSSQLSERVER → Properties.
  2. Certificate tab: select the certificate. From SQL Server 2019 Configuration Manager can also import certificates itself.
  3. Flags tab: set Force Encryption to Yes. SQL Server 2022 additionally has Force Strict Encryption (TDS 8.0, TLS before any other communication), which requires current drivers.
  4. Restart the service.

Check

SELECT session_id, encrypt_option, auth_scheme, client_net_address
FROM sys.dm_exec_connections;

encrypt_option = TRUE means encrypted. On the client side a clean connection looks like this:

Server=sql01.corp.local;Database=App;Encrypt=True;TrustServerCertificate=False;Integrated Security=True

The server name in the connection string must match a name in the certificate. With the IP address verification fails, even if the CA is trusted.

More notes

FAQ

Is TrustServerCertificate=True bad?

The connection is encrypted but not verified. Anyone in the network path can pose as the server. Fine for tests, not for production.

Does every client need the CA?

Yes, if the certificate comes from an internal CA. In a domain you distribute the root CA by group policy, then nothing else is needed.

Why doesn’t my certificate appear in the list?

Usually because of KeySpec, missing Server Authentication, or because the server name is not in the certificate. For failover clusters Configuration Manager never shows a list; there you enter the thumbprint in the registry.

Sources and documentation