Closed sake402 closed 1 year ago
@sake402 You connection string looks odd, do you really mean "user instance=true" and if so, I think you are missing:
AttachDBFilename
https://learn.microsoft.com/en-us/dotnet/framework/data/adonet/sql/sql-server-express-user-instances
Hi @sake402, usually an exception from SNI Native with a memory access violation could potential mean there's a mismatch between a compatible version of Microsoft.Data.SqlClient.SNI and Microsoft.Data.SqlClient specifically for Windows. From what I can tell so far, between EF Core 6 and EF Core 7 is that EF Core 6 uses Microsoft.Data.SqlClient version 2.1.4 and EF Core 7 uses Microsoft.Data.SqlClient version 5.0.1 and when upgrading between those version, in the documentation, it also mentions breaking changes as well. Also, as @ErikEJ mentioned, there's potentially a missing property in the connection string. Is there a sample repro project that you can provide? or are you able to try it with the missing property AttachDbFileName
or remove the user instance=true
property and see if this issue repros?
@ErikEJ Thanks for your response. I was trying a number of combination as it confuses me the source of the error. So I happen to have left that fragment there.
At your words, I however tested again with
"ConnectionStrings": {
"DefaultConnection": "Data Source=.;AttachDbFileName=C:\\TestDb.mdf;MultipleActiveResultSets=True;Integrated Security=True;User Instance=True",
},
and also
"ConnectionStrings": {
"DefaultConnection": "Data Source=.;Initial Catalog=TestDb;MultipleActiveResultSets=True;Integrated Security=True"
},
Same result. The only that works is if I downgrade to EF6.
@lcheunglci Thank for your response. I thought as much too and even tried installing Microsoft.Data.SqlClient 5.1.0, but got the same response.
@sake402 can you confirm that SNI version is accurate? We are looking for Microsoft.Data.SqlClient.SNI package. Each version of M.D.SqlClient has a dependency to a specific version of SNI. You can clean your project and build it again with dependency to M.D.SqlClient v5.1.0. Make sure that you have M.D.SqlClient.SNI or M.D.SqlClient.SNI.runtime with version of 5.1.0 as well.
Please provide a repro project.
I have the same issue. "Repro":
.csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Data.SqlClient" Version="5.1.1" />
</ItemGroup>
</Project>
Program.cs:
using Microsoft.Data.SqlClient;
var connectionString = "data source=.\\SQLEXPRESS;Integrated Security=true;AttachDBFilename=|DataDirectory|\\db.mdf;User Instance=true";
using var connection = new SqlConnection();
connection.ConnectionString = connectionString;
connection.Open();
Note that it doesn't actually matter if the database server at .\SQLEXPRESS actually exists, it doesn't even matter if the mdf file exists, simply any attempt at connecting to any server with "User Instance=true" results in access violation every single time
SqlClient is 5.1.1 and SNI runtime 5.1.0. Platform is x64 windows
I don't really care about this SQL Server feature, it's just that access violation exceptions are super nasty since they are not recoverable.
The issue started for us when we upgraded from 4.1.0 to 5.1.1
I ran a bisect on this with my repro and it broke at commit 778f86e5 aka #1608
I found the issue and will send a one-liner pull request shortly...
I'm experiencing the same after upgrading Microsoft.Data.SqlClient to 5.1.1. But only see it when running with Azure Function. If I use the class library from an Asp.net application
Given the connection string in appsettings.json
and then
It works with version 6.0.14, however because we need TPC mapping we need to use higher version, but with version 7.0.0 - 7.0.3 there is an error
Running the application results in the same exception.