Skip to content

SqlClient fails with netcoreapp2.0 on Win7/Server2008 #21116

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

Closed
smitpatel opened this issue Apr 14, 2017 · 14 comments
Closed

SqlClient fails with netcoreapp2.0 on Win7/Server2008 #21116

smitpatel opened this issue Apr 14, 2017 · 14 comments
Labels
area-System.Data.SqlClient blocking Marks issues that we want to fast track in order to unblock other important work
Milestone

Comments

@smitpatel
Copy link
Contributor

Repro steps:
Build https://github.com/aspnet/EntityFramework on windows 7 machine. All tests which uses SqlServer fails. (Tests uses localdb). Same passes in windows10/Server 2012 machines.

Exception message:

Error Message:
 System.DllNotFoundException : Unable to load DLL 'sni.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
Stack Trace:
   at System.Data.SqlClient.SNINativeMethodWrapper.UnmanagedIsTokenRestricted(IntPtr token, Boolean& isRestricted)
   at System.Data.Win32NativeMethods.IsTokenRestrictedWrapper(IntPtr token)
   at System.Data.ProviderBase.DbConnectionPoolIdentity.GetCurrent()
   at System.Data.ProviderBase.DbConnectionPoolGroup.GetConnectionPool(DbConnectionFactory connectionFactory)
   at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()

dotnet info

.NET Command Line Tools (2.0.0-preview1-005783)

Product Information:
 Version:            2.0.0-preview1-005783
 Commit SHA-1 hash:  8bd15c7ec0

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.1.7601
 OS Platform: Windows
 RID:         win7-x64
 Base Path:   C:\Users\smpatel\AppData\Local\Microsoft\dotnet\sdk\2.0.0-preview1-005783\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0-preview1-001967-00
  Build    : fa25acec41a87ce36b3ea61273d4798eb0a2486f

cc: @Eilon

@corivera
Copy link
Member

corivera commented Apr 14, 2017

sni.dll should be getting pulled down from nuget. Is that DLL present in your nuget/packages directiory?

@smitpatel
Copy link
Contributor Author

Which package to look for?

@smitpatel
Copy link
Contributor Author

More detailed repro details:
Program.cs

using System;
using System.Data.SqlClient;

namespace repor
{
    class Program
    {
        static void Main(string[] args)
        {
            var connectionString =
                @"Data Source=(localdb)\MSSQLLocalDB;Database=master;Connect Timeout=30";
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();
                Console.WriteLine("ServerVersion: {0}", connection.ServerVersion);
                Console.WriteLine("State: {0}", connection.State);
            }

            Console.WriteLine("Hello World!");
        }
    }
}

csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="System.Data.SqlClient" Version="4.3.0" />
  </ItemGroup>
</Project>

Output

Unhandled Exception: System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SNILoadHandle' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'sni.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at System.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize(IntPtr pmo)
   at System.Data.SqlClient.SNILoadHandle..ctor()
   at System.Data.SqlClient.SNILoadHandle..cctor()
   --- End of inner exception stack trace ---
   at System.Data.SqlClient.TdsParser..cctor()
   --- End of inner exception stack trace ---
   at System.Data.SqlClient.TdsParser..ctor(Boolean MARS, Boolean fAsynchronous)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, BooleanredirectedUserInstance, SqlConnectionString connectionOptions, TimeoutTimer timeout)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, Object providerInfo, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()
   at repor.Program.Main(String[] args)

@mikeharder
Copy link

This is blocking ASP.NET builds.

@weshaggard
Copy link
Member

sni.dll should be coming from https://www.nuget.org/packages/runtime.win7-x64.runtime.native.System.Data.SqlClient.sni. Can you check the assets file to make sure that it is correctly getting picked up from the tooling?

@mikeharder
Copy link

CC @davidfowl

@weshaggard
Copy link
Member

To update this issue. It was discovered the problem is that sni.dll depends on api-sets on Win7 and those are no longer included in .NET Core 2.0 shared framework. So to make this scenario work you either need to directly reference https://www.nuget.org/packages/runtime.win7-x64.Microsoft.NETCore.Windows.ApiSets/ to get the api-set shims or reference the newer version of SqlClient package (>4.4.0).

mikeharder referenced this issue in dotnet/efcore Apr 20, 2017
….0 on Win7/Server2008"

- https://github.com/dotnet/corefx/issues/18406
- Revert when `$(CoreFxVersion)` is upgraded to `4.4.0-*`
mikeharder referenced this issue in dotnet/efcore Apr 24, 2017
….0 on Win7/Server2008"

- https://github.com/dotnet/corefx/issues/18406
- Revert when `$(CoreFxVersion)` is upgraded to `4.4.0-*`
mikeharder referenced this issue in dotnet/efcore Apr 25, 2017
….0 on Win7/Server2008"

- https://github.com/dotnet/corefx/issues/18406
- Revert when `$(CoreFxVersion)` is upgraded to `4.4.0-*`
mikeharder referenced this issue in dotnet/efcore Apr 25, 2017
….0 on Win7/Server2008"

- https://github.com/dotnet/corefx/issues/18406
- Revert when `$(CoreFxVersion)` is upgraded to `4.4.0-*`
mikeharder referenced this issue in aspnet/Caching Apr 25, 2017
….0 on Win7/Server2008"

- https://github.com/dotnet/corefx/issues/18406
- Revert when `$(CoreFxVersion)` is upgraded to `4.4.0-*`
mikeharder referenced this issue in aspnet/Caching Apr 26, 2017
….0 on Win7/Server2008"

- https://github.com/dotnet/corefx/issues/18406
- Revert when `$(CoreFxVersion)` is upgraded to `4.4.0-*`
mikeharder referenced this issue in aspnet/DotNetTools Apr 27, 2017
- Addresses "SqlClient fails with netcoreapp2.0 on Win7/Server2008" (https://github.com/dotnet/corefx/issues/18406)
- Revert if and when $(CoreFxVersion) is upgraded to 4.4.0-*
mikeharder referenced this issue in aspnet/Caching Apr 27, 2017
- Addresses "SqlClient fails with netcoreapp2.0 on Win7/Server2008" (https://github.com/dotnet/corefx/issues/18406)
- Revert if and when $(CoreFxVersion) is upgraded to 4.4.0-*
mikeharder referenced this issue in aspnet/MusicStore Apr 27, 2017
- Addresses "SqlClient fails with netcoreapp2.0 on Win7/Server2008" (https://github.com/dotnet/corefx/issues/18406)
- Revert if and when $(CoreFxVersion) is upgraded to 4.4.0-*
mikeharder referenced this issue in aspnet/MusicStore Apr 27, 2017
- Addresses "SqlClient fails with netcoreapp2.0 on Win7/Server2008" (https://github.com/dotnet/corefx/issues/18406)
- Revert if and when $(CoreFxVersion) is upgraded to 4.4.0-*
mikeharder referenced this issue in aspnet/DotNetTools Apr 27, 2017
- Addresses "SqlClient fails with netcoreapp2.0 on Win7/Server2008" (https://github.com/dotnet/corefx/issues/18406)
- Revert if and when $(CoreFxVersion) is upgraded to 4.4.0-*
mikeharder referenced this issue in aspnet/Benchmarks Apr 29, 2017
- Addresses "SqlClient fails with netcoreapp2.0 on Win7/Server2008" (dotnet/corefx#18406)
- Revert if and when $(CoreFxVersion) is upgraded to 4.4.0-*
mikeharder referenced this issue in aspnet/Benchmarks May 1, 2017
- Addresses "SqlClient fails with netcoreapp2.0 on Win7/Server2008" (dotnet/corefx#18406)
- Revert if and when $(CoreFxVersion) is upgraded to 4.4.0-*
@twDuke
Copy link

twDuke commented Aug 30, 2017

Using dapper 1.50.2, which has a dependency on SqlClient 4.1, caused this issue. Explicitly installing SqlClient 4.4 indeed solved the issue.

@johnmckay-reward
Copy link

@twDuke This applies to ServiceStack.OrmLite.SqlServer aswell, explicitly installing 4.4 fixes things!

@hanssens
Copy link

Same issue with NPoco v3.8.0 - manually adding System.Data.SqlClient as a nuget package (v4.4.0) fixed it for me as well.

Minor note: I only had the error during deploy to Azure and not when debugging on localhost.

@geschw66
Copy link

I have an ASP .NET Core MVC project that is getting this error. Are you saying I need to simply install the
the package: System.Data.SqlClient version 4.4.0 or ???

PM> Install-Package System.Data.SqlClient -version 4.4.0

Is this what I need to do to avoid the above described exception?

@BrandonClapp
Copy link

I had the same sni.dll error. Installing System.Data.SqlClient (I installed 4.4.2) worked to fix the problem.

@geschw66 Did installing the package fix the issue for you?

@besley
Copy link

besley commented May 15, 2019

.net core 2.1, System.Data.SqlClient 4.6.1 meet the same issue. After install Microsoft.AspNetCore.All 2.1.11 fixed the issue.

@hanssens
Copy link

@besley Good to know. BTW, please be aware that from dotnet core 2.2 and higher, the Microsoft.AspNetCore.All package doesn't include System.Data.SqlClient anymore. This means from v2.2+ and higher. Should you upgrade in the future to that version, you still need to manually reference System.Data.SqlClient in that case.

Also the Microsoft.AspNetCore.All is quite a big package. If you don't have a direct need for it, it's best to not reference all the stuff in there.

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.0.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Data.SqlClient blocking Marks issues that we want to fast track in order to unblock other important work
Projects
None yet
Development

No branches or pull requests