Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Databases and Redis · Troubleshooting walkthrough

Visual Studio cannot reach SQL Server because the pre-login TLS handshake is cut off

Short answer

SQL Server error 10054, An existing connection was forcibly closed by the remote host during the pre-login handshake, is a failed TLS handshake. Usually a Windows 11 client (TLS 1.0 and 1.1 off) meets a server without TLS 1.2, no cipher suite is shared, or the server certificate uses MD5, SHA224 or SHA512. Encrypt=False does not avoid it.

  • Applies to Microsoft.Data.SqlClient 7.1, Windows 11, Windows Server 2022 and later, ODBC Driver 17/18 for SQL Server, .NET Framework 4.6.2 and later
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Error 10054 during the pre-login handshake is raised by the Windows sockets layer when the other side closes the connection. For SQL Server, Microsoft ties it to a failed TLS handshake: the two machines found no shared protocol version or cipher suite, or the server offered a certificate that TLS 1.2 cannot use. No sign-in has happened yet, so the cause is never your password or login.

Four things break the handshake, and each leaves a different trace. The walkthrough reads the evidence in the order that rules out the cheapest ones first.

The text you see

  • A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)
  • A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - An existing connection was forcibly closed by the remote host.)
  • An existing connection was forcibly closed by the remote host (OS error 10054)

Stage 1

What the handshake needs from both sides

During pre-login SQL Server and the client set up a TLS channel to carry the credentials. SQL Server always encrypts the sign-in packets, which is why changing Encrypt=False in the connection string does not avoid this error. If the two sides share no protocol, or no cipher suite, the server simply closes the socket, and the client reports 10054.

TLS versionWindows statusWhat to do
1.0 and 1.1Off by default on Windows 11 and Windows Server 2022 and laterDo not rely on them; upgrade the old side
1.2On by default on supported WindowsThe baseline every SQL Server client should reach
1.3Windows 11 and Server 2022 and later; SQL Server 2022 and later with current driversUsed where both sides support it

Stage 2

Rule out an old client or server

The usual case today is a Windows 11 client with TLS 1.0 and 1.1 off meeting an old SQL Server build or an old driver that cannot speak TLS 1.2. Microsoft lists safe client baselines: ODBC Driver 17 or 18, OLE DB Driver 18 or 19, .NET Framework 4.6.2 or later or modern .NET, and JDBC Driver 9.4 or later. SQL Server Native Client and the old SQLOLEDB provider are deprecated and are the usual offenders.

The permanent fix is to update the driver or move SQL Server to a build with TLS 1.2 support. Turning TLS 1.0 back on, on both machines, is a stopgap until that is done.

Stage 3

Look for a weak certificate

SQL Server picks up any certificate in the machine store that allows server authentication, even one nobody assigned to it. If its hash algorithm is MD5, SHA224 or SHA512, TLS 1.2 cannot use it and the handshake ends. A certificate SQL Server generates for itself is not affected.

The error log shows which certificate was loaded for encryption, with its hash. In SQL Server Configuration Manager, open the instance's Protocols properties and read the Certificate tab; if one is listed, view it, then clear it. If none is shown, find it by thumbprint in the Certificates snap-in for the computer account, open its properties, choose Enable only the following purposes, and clear Server Authentication. Restart the SQL Server service afterwards.

Stage 4

Compare cipher suites

A hardened machine can speak TLS 1.2 and still share no suite with its peer. A network trace shows it: the client's Client Hello is followed by a closed connection instead of a Server Hello. Without a trace, list what each side has enabled.

Enabled suites, in two forms

Get-TlsCipherSuite | Select-Object Name
Get-ItemPropertyValue -Path 'HKLM:\System\CurrentControlSet\Control\Cryptography\Configuration\Local\SSL\00010002\' -Name Functions

Enable-TlsCipherSuite adds a suite without a restart; keep the client and server baselines the same.

Stage 5

The Diffie-Hellman case

When the two ends run different Windows generations and both advertise TLS_DHE_ suites, the handshake can fail because the releases handle the key exchange differently, or because one side lacks the leading-zero update. Microsoft's remedy is to stop offering those suites by removing every name that starts with TLS_DHE_ from the local policy of the affected machine.

One suite at a time, repeat for each DHE name

Disable-TlsCipherSuite -Name 'TLS_DHE_RSA_WITH_AES_256_GCM_SHA384'

Stage 6

If none of those fits

Microsoft also lists 10054 after an upgrade, on linked servers, on a new Always On node, and under heavy sign-in load on SQL Server 2017 or earlier, where a shortage of connection-accept workers causes the handshake to time out. Capture a trace on both machines and compare the Hellos before changing more settings.

If you only keep one thing

  • 10054 at pre-login means the TLS handshake failed; credentials were never checked.
  • Check protocol, then certificate hash, then cipher suites, then DHE.
  • Encrypt=False cannot help because sign-in packets are always encrypted.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. 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.

Next step

Want a second pair of eyes on it?

Send me the error and what changed before it started. I reply within 24 hours.