Skip to content

System.DllNotFoundException: 'The DLL 'Microsoft.Data.SqlClient.SNI.x86.dll' could not be loaded: The specified module could not be found. (Exception from HRESULT: 0x8007007E)' #3260

Closed as not planned
@MojoDK

Description

@MojoDK

Describe the bug

If I create a .Net Framework 4.8 vb.net Winform app and add Microsoft.Data.SqlClient, every thing works fine. If I create a .Net Framework 4.8 vb.net Web (MVC) application and add Microsoft.Data.SqlClient, then I get the error.

Screeencast:
https://app.screencast.com/Awqe1liwal6hi?conversation=jS1SXY0TcTEHZQMhG0tMH1

Exception message:
System.DllNotFoundException: 'The DLL 'Microsoft.Data.SqlClient.SNI.x86.dll' could not be loaded: The specified module could not be found. (Exception from HRESULT: 0x8007007E)'

Stack trace:
System.DllNotFoundException
  HResult=0x80131524
  Message=DLL'en 'Microsoft.Data.SqlClient.SNI.x86.dll' kunne ikke indlæses: Det angivne modul blev ikke fundet. (Undtagelse fra HRESULT: 0x8007007E)
  Source=Microsoft.Data.SqlClient
  StackTrace:
   at Microsoft.Data.SqlClient.SNINativeManagedWrapperX86.UnmanagedIsTokenRestricted(IntPtr token, Boolean& isRestricted)
   at Microsoft.Data.SqlClient.SNINativeMethodWrapper.UnmanagedIsTokenRestricted(IntPtr token, Boolean& isRestricted)
   at Microsoft.Data.Win32NativeMethods.IsTokenRestrictedWrapper(IntPtr token)
   at Microsoft.Data.ProviderBase.DbConnectionPoolIdentity.GetCurrentNative()
   at Microsoft.Data.ProviderBase.DbConnectionPoolGroup.GetConnectionPool(DbConnectionFactory connectionFactory)
   at Microsoft.Data.ProviderBase.DbConnectionFactory.GetConnectionPool(DbConnection owningObject, DbConnectionPoolGroup connectionPoolGroup)
   at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at Microsoft.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
   at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry, SqlConnectionOverrides overrides)
   at Microsoft.Data.SqlClient.SqlConnection.Open(SqlConnectionOverrides overrides)
   at Microsoft.Data.SqlClient.SqlConnection.Open()
   at WebApplication2.HomeController.Index() in D:\Develop\Projects\_Ic.Core\_Test\Diverse\WebApplication2\WebApplication2\Controllers\HomeController.vb:line 8
   at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
   at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c.<BeginInvokeSynchronousActionMethod>b__9_0(IAsyncResult asyncResult, ActionInvocation innerInvokeState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`2.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_0.<InvokeActionMethodFilterAsynchronouslyRecursive>b__0()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass11_2.<InvokeActionMethodFilterAsynchronouslyRecursive>b__2()

To reproduce

  1. Create a VB.Net Framework 4.8 Web MVC application
  2. Add Microsoft.Data.SqlClient Nuget package
  3. Update all packages
  4. In the HomeController Index method, add a new sqlconnection:
    Dim cnn As New SqlConnection("Data Source=MySever;Initial Catalog=MyDb;Persist Security Info=True; Integrated Security=true; application name=abc; Min Pool Size=1; Connection Timeout=30; TrustServerCertificate=True;")
    cnn.Open()
  5. Run the application and the error occurs
Imports Microsoft.Data.SqlClient

Public Class HomeController
    Inherits System.Web.Mvc.Controller

    Function Index() As ActionResult
        Dim cnn As New SqlConnection("Data Source=MyServer;Initial Catalog=MyDb;Persist Security Info=True; Integrated Security=true; application name=abc; Min Pool Size=1; Connection Timeout=30; TrustServerCertificate=True;")
        cnn.Open()
        Return View()
    End Function

    Function About() As ActionResult
        ViewData("Message") = "Your application description page."

        Return View()
    End Function

    Function Contact() As ActionResult
        ViewData("Message") = "Your contact page."

        Return View()
    End Function
End Class

Expected behavior

A new SqlConnection is created and opened.

Further technical details

Microsoft.Data.SqlClient version: 6.0.1
Microsoft.Data.SqlClient.Sni version: 6.0.2
.NET target: .NET Framework 4.8, .NET 6.0
SQL Server version: SQL Server 2022
Operating system: Windows 11 Pro x64

Additional context

Metadata

Metadata

Assignees

Labels

Needs More Info ℹ️Issues that have insufficient information to pursue investigationsWaiting for Customer ⏳Issues/PRs waiting for user response/action.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions