Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x86.dll' #727

Closed
jonathan-timothy-mason opened this issue Sep 16, 2020 · 35 comments
Closed
Labels
Area\Native SNI Issues that are targeted to the Native SNI codebase.

Comments

@jonathan-timothy-mason
Copy link

Hi,

I have migrated our .NET 4.7.2 x86 solution to Microsoft.Data.SQLClient v2.0.1 using Nuget.

When running our program in Windows 10 64-bit, the error below occurs:
Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x86.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

If I look at the bin folder of our project that deals with the database, which has a dependency on Microsoft.Data.SQLClient, I find:
Microsoft.Data.SqlClient.dll
Microsoft.Data.SqlClient.SNI.x86.dll
Microsoft.Data.SqlClient.SNI.x64.dll

However, if I look at the bin folder of our executable project, which does not have a dependency on Microsoft.Data.SQLClient, but only on our database project, I only find:

Microsoft.Data.SqlClient.dll

If I copy the missing assemblies into the executable bin folder, the problem is solved.

I assume this is a problem with Nuget. What is the best way to solve this without manually copying the missing dependecnies. We have several exeutables.

Upgrading to Nuget 5 didn't help.

Thanks
Jon

@ErikEJ
Copy link
Contributor

ErikEJ commented Sep 16, 2020

Reference the MDS package directly in the .exe projects.

@karinazhou
Copy link
Member

karinazhou commented Sep 16, 2020

Hi @jonathan-timothy-mason , as what @ErikEJ suggested, you need reference the Microsoft.Data.SqlClient nuget package directly in your executable project so the nuget manager is able to copy SNI dlls to the target bin folder. Please feel free to try it and see whether it works.


And one more thing to check, what type is the .NET framework project you are working on? Is it a WebForms project or just a common .NET Framework project? We have some known issues about WebForms project #446 .

@jonathan-timothy-mason
Copy link
Author

jonathan-timothy-mason commented Sep 17, 2020

Thanks for your replies @ErikEJ and @karinazhou. To sum up, anything with a dependency on a project using Microsoft.Data.SQLClient doesn't get Microsoft.Data.SqlClient.SNI.xxx.dll copied to it's bin folder. Is that right?

Do you think unit test projects that have a dependency on our database project would also need to be made to directly reference Microsoft.Data.SQLClient too?

Thanks a lot.
@jonathan-timothy-mason

@ErikEJ
Copy link
Contributor

ErikEJ commented Sep 17, 2020

To sum up, anything with a dependency on a project using Microsoft.Data.SQLClient doesn't get Microsoft.Data.SqlClient.SNI.xxx.dll copied to it's bin folder. Is that right?

No, that is not right. This works as expected in most scenarios, so please provide a repro solution.

@cheenamalhotra cheenamalhotra added the Area\Native SNI Issues that are targeted to the Native SNI codebase. label Sep 18, 2020
@jonathan-timothy-mason
Copy link
Author

Our projects typically reference our data access project, which itself directly references Microsoft.Data.SQLClient. I've included a document, which lists all our top-level projects, and says which experience the "Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x86.dll'" error.

Our solution has 66 projects and I don't think it would be possible to simplify it into a form that I can send to you, which would still accurately reproduce the same problem.

Top-Level Projects and “Unable to load DLL 'Microsoft.Data.SqlClient.SNI.x86.dll'” Error.pdf

@ErikEJ
Copy link
Contributor

ErikEJ commented Sep 24, 2020

Please provide a .csproj file of a failing "top level" project.

@jonathan-timothy-mason
Copy link
Author

Hi @ErikEJ, attached is the project file for our main Windows Forms project that does not reference Microsoft.Data.SQLClient directly, but does reference the other projects MatrixDAL, MatrixBLL, MatrixBLLBase, MatrixBllDalShared, which do directly reference it directly.

UI - Windows.zip

@karinazhou
Copy link
Member

@jonathan-timothy-mason I looked at the pdf file you attached and all the failing scenarios, except for the VSTest one, can be fixed by directly adding driver's Nuget reference to the top-level project.

This is the known issue for native SNI.dll. I think, for now, you may have to directly reference driver nuget in your main project as a workaround.

@jonathan-timothy-mason
Copy link
Author

OK, thanks for your help @karinazhou, we'll probably wait until it's been fixed to avoid all the unnecessary references.

@cheenamalhotra
Copy link
Member

Hi @jonathan-timothy-mason

As I replied here: #446 (comment)
The same applies to any .NET Framework application, could you verify and confirm the feasibility to import SNI targets?

@aibrahim2020
Copy link

@jonathan-timothy-mason I looked at the pdf file you attached and all the failing scenarios, except for the VSTest one, can be fixed by directly adding driver's Nuget reference to the top-level project.

This is the known issue for native SNI.dll. I think, for now, you may have to directly reference driver nuget in your main project as a workaround.

I'm facing the same issue but with visio Add-in project!! there is no Bin folder when you publish the add-in

@gaganpandey1977
Copy link

gaganpandey1977 commented Feb 13, 2021

I tried all these options nothing work for me. I see when i am compiling or publishing the web Application to a folder i see Microsoft.Data.SqlClient.SNI.x86.dll and Microsoft.Data.SqlClient.SNI.x86.pdb inside Bin folder. However when i publish this to Cloud this file i missing.
I added these lines to .csproj file too.


@gaganpandey1977
Copy link

@cheenamalhotra any thoughts why my web app is not copying this dll into Bin folder . I explicitly added reference as mention above in .csproj file too.

@cheenamalhotra
Copy link
Member

If you could upload a repro app, we can take a look and get back to you!

@norcisa-andy
Copy link

I have experienced the same issue but with the x64 version.

@sliddington
Copy link

Just added a "better" workaround on the other thread #446 (comment)

@jgcjoec
Copy link

jgcjoec commented Apr 2, 2021

I had the same issue and used a post-build event to copy the missing DLL. That worked fine, until Windows file locking put up a roadblock. For reasons unknown, IIS had the file locked. Is there any way to disable Windows file locking entirely or to disable it in certain use-cases?

@benmccallum
Copy link

benmccallum commented Aug 2, 2021

We have a similar issue, but on a couple of ASP.NET MVC 5 projects and an ASP.NET Web API 2 project, all targeting net472.

Unfortunately, even with the proposed workaround, we still don't get the SNI files into our nupkg produced by Octopack, so they don't get deployed. Actually the workaround here was not required, we were still getting the files in the bin, it's just Octopack wasn't picking them up.

I can see the SNI files copy step in the build log, but the Octopack one after it never copies them over, I imagine because the existence of them is not being passed along to it.
image

I resolved it by explicitly declaring them as files in the nuspec... (Octopack docs). Pretty nasty though.

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <files>
    <!-- https://github.com/dotnet/SqlClient/issues/727 -->
    <file src="bin\Microsoft.Data.SqlClient.SNI.*.*" target="bin" />

Aside: Likely a stupid question, but would running dotnet msbuild make any difference? I do have a backlog item to get us off the deprecated TeamCity VS Solution build step, so I could try that if someone thinks it will.

@cheenamalhotra
Copy link
Member

Hi @benmccallum

dotnet msbuild internally executes using MSBuild, so it should give you the same experience as msbuild. It may not change anything in regards to whether the files are copied or not. Unless the copy targets are included in your csproj, they are native DLLs and will not be identified by Dotnet SDK.

@benmccallum
Copy link

Thanks for confirming @cheenamalhotra , I figured as much.

@jzabroski
Copy link

What does SNI stand for ? Can probably put together several repros if I understand what's special about this dll

@jzabroski
Copy link

To elaborate, https://github.com/dotnet/SqlClient/labels does not even have a description for "Native SNI"

It looks like this document explains it: https://docs.microsoft.com/en-us/sql/connect/ado-net/sqlclient-troubleshooting-guide?view=sql-server-ver15

Unable to load native SNI (Server Name Indication) library

SNI is the native C++ library that SqlClient depends on for various network operations when running on Windows. In .NET Framework applications that are built with the MSBuild Project SDK, native DLLs aren't managed with restore commands. So a ".targets" file is included in the "Microsoft.Data.SqlClient.SNI" NuGet package that defines the necessary "Copy" operations.

@swePeso
Copy link

swePeso commented Dec 26, 2022

SSMS 19.4 have the same problem. 19.3 did not have this problem.

@brain246
Copy link

brain246 commented Jan 18, 2023

and the same here. since updating SSMS to preview 4 i cannot connect to any sql instances anymore.

solved in my case: see below

@reinaldokibel
Copy link

same here with SSMS 19 Preview 4 on some servers, not all the servers

@asamaras
Copy link

Same here, with ssms 19 preview 4, no connection to any server via IP address.

@cheenamalhotra
Copy link
Member

@swePeso @brain246 @reinaldokibel @asamaras

Could you please provide more info to help us reproduce the issues you're facing with SSMS? Is that something you also reproduce from a .NET Framework Console app with Microsoft.Data.SqlClient?

cc @shueybubbles

@brain246
Copy link

brain246 commented Jan 24, 2023

@cheenamalhotra Sorry, can't be of any help anymore regarding this issues, as it is now solved on my machine (after de-installing and reinstalling it....).

I might have to add that i had several versions of Azure Data Studio (Insiders), VSCode, Visual Studio (2019, 2022) and two instances of SSMS (18 and 19) installed before (yeah, i know... 😄) . After cleaning that mess up and re-installing SSMS19/Preview4 it worked, but in the end i cannot say what did the trick or caused the issue (but maybe that can be a hint for others here...).

@asamaras
Copy link

Hi @cheenamalhotra ,
Steps to reproduce:

  1. PC with Windows 10/64 bit 19045.2486
  2. Download and install SSMS-Setup-ENU.exe from https://go.microsoft.com/fwlink/?linkid=2219772&clcid=0x409 (version 19.4 preview)
  3. Install the application
  4. Connect to a local DB instance via windows authentication, the connection should be successful
  5. Connect to a server via IP and you get the error message.

Update:
After uninstalling, rebooting and re-installing SSMS managed to connect to DB server without issues.

@JRahnama
Copy link
Contributor

@asamaras have you tried using FQDN or server name instead of IP address? This could be due to the new feature HostNameInCertificate

@asamaras
Copy link

@JRahnama That indeed could explain it, the server name is set to a local domain but the terminal is not consulting it, I use host file, so there is a possibility that it could not get the certificate from the server. I use IP to connect.
Most likely I need to setup an AD domain.

@Uj947nXmRqV2nRaWshKtHzTvckUUpD

I went to add/remove programs and ran repair on it, which fixed the problem

@Ahmad-Hamdeen
Copy link

Ahmad-Hamdeen commented Feb 20, 2023

This method had worked with me 👉 if this file "Microsoft.Data.SqlClient.SNI.x86.dll"
is not exists in this path:
"C:\Program Files (x86)\Microsoft SQL Server Management Studio 19\Common7\IDE"
Steps:
1.Download the file from this link https://www.mediafire.com/file/z2wjnd8vzg9vdf4/Microsoft.Data.SqlClient.SNI.x86.dll/file
2.Copy and Past it to "C:\Program Files (x86)\Microsoft SQL Server Management Studio 19\Common7\IDE"
3.Run the SQL Server Management Studio Management Studio 19 (Worked with me ✔)

@David-Engel
Copy link
Contributor

David-Engel commented Jun 11, 2024

Closing this issue as it appears to be external and has no specific fix to be made in MDS. This is also likely a duplicate of #612

@David-Engel David-Engel closed this as not planned Won't fix, can't repro, duplicate, stale Jun 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area\Native SNI Issues that are targeted to the Native SNI codebase.
Projects
Development

No branches or pull requests