If you use Entity Framework Core 3.1.x with SQL Server from a Linux machine, consider updating to use a more recent version of Microsoft.Data.SqlClient.

Some background

Microsoft.Data.SqlClient is the library used by EF Core 3 to connect to SQL Server and Azure SQL Database. EF Core 3.x currently depends on version 1.0.19269.1 of this library. Recently, a hotfix release was published to NuGet, which included a bug fix for a deadlock issue introduced in this PR.

However, EF Core will not use the updated release version, unless you tell it to do so.

You can do that by adding a single line to your .csproj file that currently references the Microsoft.EntityFrameworkCore.SqlServer package.

<PackageReference Include="Microsoft.Data.SqlClient" Version="1.1.1" />

<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.2" />

Luckily, it looks like the EF Core team will update to use this never dependency in a future patch release of 3.x.

Why is this a Linux only issue?

Microsoft.Data.SqlClient contains a component that is responsible for the actual communication with SQL Server via the TDS protocol over the network. On Linux, this component is an open source implementation, called "Managed SNI", written in C#. On Windows, this component is currently a closed source implementation, written in C / C++ (unmanaged code). And the bug was only present in the Managed SNI component.

Why the closed source component is still in use on Windows is presumably for performance reasons, and due to a missing Windows authentication feature.

However, it looks like there could be plans in motion to also use the C# implementation on Windows eventually.

Comments or questions?