SqlClient: Error code 139 when attempting Microsoft.Data.SqlClient connection on Linux with net6.0
I get error code 139 when attempting Microsoft.Data.SqlClient connection on Linux with net6.0 (6.0.100). I see the error when using dotnet watch run
, otherwise it exits silently. The same code works on net5.0.
watch : Exited with error code 139
To reproduce
app.fsproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="3.0.1" />
</ItemGroup>
</Project>
Program.fs
open System
open Microsoft.Data.SqlClient
let server = Environment.GetEnvironmentVariable("SERVER")
let connectionString = $"Server={server};Trusted_Connection=True;"
let cnxn = new SqlConnection(connectionString)
cnxn.Open() // program silently exits here (or with code 139 if using watch)
printf "connection is open"
cnxn.Close()
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 5
- Comments: 56 (32 by maintainers)
@stcpottdav we are planning a hotfix release around January 15 of 2022. The release will include some other fixes as well.
I think this is dup of https://github.com/dotnet/runtime/issues/60906. The linked breaking change only impact HttpClient in cases it tries to generate SPN on it’s own.
This worked for me, thank you!
@Palsternakka Microsoft.EntityFrameworkCore.SqlServe is using M.D.SqlClient v2.1.4. Can you overwrite the version in the csproj file by adding packageReference to version 4.1? The issue was addressed first in v4.0.1 and is not back ported to previous versions yet.
We have been getting this issue as well. Couldn’t use the assembly above since it’s all done through EF in the application, but we did get a temporary work around until the an official update that can replace the downstream nuget package.
Adding the EnsureGssInitialized() method call in the program.cs stopped the error.
We are planning on a hotfix from our side sometime soon. Time will be announced soon.
I’ve been struggling trying to upgrade our .NET 5 API to .NET 6 with for days! We host our API on a Linux containers in Kubernetes. The container kept crashing and I saw that it threw a
Segmentation fault (core dumped).
error. Explicitly referencing Microsoft.Data.SqlClient 4.1.0 worked for me!@ladeak as an alternative you can use this package with MDS 4
https://www.nuget.org/packages/ErikEJ.EntityFramework.SqlServer/
I have run into the same issue. I have tested the suggested nuget package:
Microsoft.Data.SqlClient
version 4.1.0, and in .net6 + RHEL 8 I don’t get segfault anymore with EntityFrameworkCore.However, using EntityFramework (the non-core version) version 6.4.4, I still face the issue. The workaround by @clbiggs seems to work there.
Should there be a bugfix in
System.Data.SqlClient
package too? (I believe that is being used by the classic EntityFramework)BTW, this would be for 6.0.4 to release in April. Meantime perhaps someone would like to explicitly paste in the code necessary to workaround, that was mentioned above, for the ease of others.
@JRahnama unfortunately I don’t have any possibility to test with MDS personally. Will ask a colleague tomorrow … he might have the necessary environment to test
yes, this was done late (unfortunately) in 6.0. So either wrap it In try/catch or even better
Long run, I would like to add enough public surface so SqlClient (and others) do not need to depend on private functions. We missed 6.0.1 maintenance and next one will be early next year. If you can do anything faster it would be great @JRahnama. If there is new package available, please ping both threads so people can try it.
I am having the same issue. After running a test, I used dmesg to show where the segmentation fault happened: dotnet[659]: segfault at 0 ip 00007fdc7e8a63bc sp 00007ffe5b10db70 error 4 in libSystem.Net.Security.Native.so[7fdc7e8a6000+1000]
That’s not the issue for two reasons:
netcoreapp3.1
my app works, and that doc indicates 3.x behavior should be the same as 6.DOTNET_SYSTEM_NET_HTTP_USEPORTINSPN=1
, and just to be certain also set the context switchAppContext.SetSwitch("System.Net.Http.UsePortInSpn", true)
. The net6 version of this still crashes.