How to Apply Force Encryption in SQL Server

If you’re planning to allow external connections to a SQL Server, one of the first security measures to implement is encryption, both at rest and in transit.

SQL Server provides an option to force encryption for all connections, ensuring secure SQL connectivity. This guide walks you through the steps to enforce encryption, following Microsoft’s official documentation: Enable Encrypted Connections to the Database Engine. Given the complexity of this process, it’s essential to review the official docs thoroughly before proceeding.

What This Guide Covers:
1. Creating a Certificate for SQL Server
2. Importing the Certificate to Trusted Root Certificates
3. Importing the Certificate into SQL Server
4. Forcing Encryption in SQL Server
5. Verifying Encrypted SQL Server Connections


1. Creating a Certificate for SQL Server

A certificate issued for Server Authentication is required, and its name must match the fully qualified domain name (FQDN) of the server.

For this tutorial, we’ll use PowerShell to create a new self-signed certificate. Modify the output file location and DNS names to match your environment if you are using this script.

# Create a new self signed certificate
New-SelfSignedCertificate -DnsName lab-sql1.whyte.net -CertStoreLocation cert:\LocalMachine\My -FriendlyName lab-sql1-cert -KeySpec KeyExchange -NotAfter (get-date).AddYears(99)
$thumbprint = $(Get-ChildItem Cert:\LocalMachine\My).thumbprint
$Pwd = ConvertTo-SecureString -String "Str0ngePassword1!" -Force -AsPlainText
Export-PfxCertificate -Cert "Cert:\LocalMachine\My\$thumbprint" -FilePath "C:\temp_certificates\lab-sql1pk.pfx" -Password $Pwd -Force
PowerShell Create Self Signed Certificate

Here’s the output .pk file:

Certificate File Windows Explorer

2. Importing the Certificate to Trusted Root Certificates

1. Open Microsoft Management Console (MMC), and add the Certificates (Local Computer) Snap-in.

MMC Local Computer
MMC Console

2. Expand Trusted Root Certification Authorities.

3. Right-click and select All Tasks > Import.

Trusted Root Certificate Import

4. Navigate to the .pfx file.

Import pfx File

5. Enter a password & continue.

Private Key Password

6. Finish up the wizard.

Certificate Import Wizard

7. Verify the imported certificate in MMC.

MMC

3. Importing the Certificate into SQL Server

1. Open SQL Server Configuration Manager.

2. Right-click Protocols for MSSQLSERVER and select Properties.

SQL Server Protocols

3. Open the Certificate tab and you should be able to view & select the new certificate from the drop-down menu.

4. Click to Apply & Ok out of the window – I’m doing the Forcing of Encryption separate next.

Protocols for MSSQLSERVER

You’ll get this prompt.

Any changes made will be saved, however, they will not take effect until the service is stopped and restarted

Now, restart the SQL Services from the configuration manager.

SQL Server Configuration Manager

If your services don’t start back up again, then ensure the service accounts have the appropriate permissions. For this demo, my AD Service Accounts are members of the local Administrators group.

4. Forcing Encryption in SQL Server

To force connections to be encrypted in SQL Server:

1. In SQL Server Configuration Manager, right-click Protocols for MSSQLSERVER and select Properties.

2. Within the Flags tab, enable Force Encryption.

SQL Server Force Encryption

3. Restart the SQL Services.

SQL Server Service Restart

5. Verifying Encrypted SQL Server Connections

Now that we have configured our SQL Server to force connections to be encrypted, lets verify that’s the case.

1. Open SSMS and connect to the SQL Server.
You may now have to ensure the Encrypt connection & Trust server certificate options are checked!

SSMS Connection Properties

2. Once connected, query the sys.dm_exec_connections table and check the encryption_option column for all the incoming SQL connections.
Checkout the MS Docs as linked for more information on the meaning behind the information displayed below.

-- check if connections are encrypted (encrypt_option col)
SELECT * 
FROM sys.dm_exec_connections
sys.dm_exec_connections

I hope this guide provided clear and actionable steps to help you configure forced encryption in SQL Server!


Comments

One response to “How to Apply Force Encryption in SQL Server”

  1. Joe S Avatar
    Joe S

    I ran through this and it worked fantastic. Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *

Recent Posts
Categories
Tags

Always On Availability Groups (AAG) (4) AWS (4) AWS Redshift (6) Database Admin (72) Database Backups & Recovery (14) Database Mirroring (2) Error Messages (5) Failover Cluster Instances (FCI) (1) Git Commands (6) Importing & Exporting Data (2) Linked Servers (3) Linux Administration (2) Logging & Monitoring (1) Microsoft Patching (2) MySQL (4) Postgres (6) PowerShell Scripts (2) SQL Certificates & Encryption (3) SQL Server Agent (5) SQL Server CDC (2) SQL Server Data Types (2) SQL Server Management Studio (SSMS) (17) SQL Server Networking (3) SQL Server on Linux (1) SQL Server Patching (2) SQL Server Performance Tuning (6) SQL Server Processes (SPIDs) (7) SQL Server Replication (2) SQL Server Scripts (13) SQL Server Security (4) SQL Server Storage (10) Windows Admin (20) Windows Authentication (2) Windows Automation (1) Windows Events (2) Windows Firewall (4) Windows Subsystem for Linux (WSL) (18)