dotnet / SqlClient

Microsoft.Data.SqlClient provides database connectivity to SQL Server for .NET applications.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MicroSoft.Data.SqlClient is not supported on this platform SNI issue

hietshkumar10 opened this issue · comments

Microsoft.Data.SqlClient is not supported on this platform

Created a class library that is running SQL query using Microsoft.Data.SqlClient.

Used DLL of that class library in console app (Including MIcrosoft.Data.SQLClient.dll)

When running method of class library getting above error

If referring f MIcrosoft.Data.SQLClient.dll from runtimes\win\lib\net6.0 error got changed to (DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.dll)

And if trying to add reference of Microsoft.Data.SqlClient.SNI.dll giving Bad IL format issue

Same thing happening if achieving above with code.

(Creating components to existing .net6 Component Manager )

**Exception message:**
DllNotFoundException: Unable to load DLL 'Microsoft.Data.SqlClient.SNI.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)


### Further technical details
**Working ** 
1. If switching AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows", true); Setting this at stating working fine but this is not recommended to use by Microsoft
3. **If referring MIcrosoft.Data.SQLClient.dll from runtimes\unix\lib\net6.0 it also works fine Don't know why but it doesn't seems good solution and can't use.**
4.  If installing the Microsoft.Data.SqlClient in console app (Can't update existing Component handler)

**using .Net6 VS 2022 Checked** 

@hietshkumar10, try copying the Microsoft.Data.SqlClient.x64.dll or Microsoft.Data.SqlClient.x86.dll, based on the application architecture, from same folder you copied Microsoft.Data.SqlClient.dll from. That should address your issue.

**Working **

  1. If switching AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows", true); Setting this at stating working fine but this is only recommended to use by Microsoft

This will use managed SNI, which means you wont need the native SNI dll.

If referring MIcrosoft.Data.SQLClient.dll from runtimes\unix\lib\net6.0 it also works fine Don't know why but it doesn't seems good solution and can't use.

If you are on windows this is not a good solution. You can refer to runtimes\win dlls and see if that solves the issue for you.

If you handle DLLs and their dependencies, your application may behave differently if you choose the wrong DLL. It is important to select the correct runtime DLL based on your application's setup.

image

https://learn.microsoft.com/en-us/sql/connect/ado-net/appcontext-switches?view=sql-server-ver16

Can we use this in production(**Going to use on Windows Environment only **)?

@JRahnama

@hietshkumar10 there is no issue using ManagedSNI on production, if you are not using MARS (known issue #422 ) everything should work as before.

To add more, our long term goal is to move away from native libraries and convert everything to managed. A work is in progress to achieve that goal in netcore and after that moving to netfx.