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

Cannot connect to (localdb) from .NET Core except via Named Pipe on Windows 11 ARM #1441

Open
benday opened this issue Dec 22, 2021 · 32 comments
Assignees

Comments

@benday
Copy link

benday commented Dec 22, 2021

Description

I'm trying to connect to SQL Server Express LocalDB from .NET Core 6 on Windows 11 ARM. If I use a connection string that refers to it using the instance name "Data Source=(localdb)\MSSQLLocalDB", it fails with the exception below. If I connect to it using a named pipe, it works.

Microsoft.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SNI_PN11, error: 56 - Unable to load the SQLUserInstance.dll from the location specified in the registry. Verify that the Local Database Runtime feature of SQL Server Express is properly installed.) ---> System.ComponentModel.Win32Exception: %1 is not a valid Win32 application.

I've created some simple MSTest unit tests to repro the problem. There are two test methods in the DatabaseConnectionFixture class that attempt to connect to LocalDB: one uses an ordinary connection string and the other uses a named pipe. On Windows 11 ARM, the ConnectToDatabase_ConnectionString() method fails. If I run this same code on Windows 11 x64, both tests pass.

Configuration

This is running on Windows 11 ARM in a Parallels VM on an M1 MacBook Pro. The OS Build # is 22509.1011. The dotnet core build is 6.0.100.

@JRahnama
Copy link
Contributor

JRahnama commented Dec 22, 2021

@benday, I have not looked into the repro you have provided or much in details just some quick notes, have you tried with ssms to see if that gets a connection? LocalDb can use two different connection strings.

  1. (localdb)\<Instance name> or (localdb)\.\<shared instance name> or (localdb)\.. Last one connects to default local db which is MSSQLLocalDB

  2. np:\.\pipe\LOCALDB#\tsql\query

The first one should be working without any issues, but there is an open issue for second one #1395 and PR #1433 is made to address issue.

One other problem with Instance pipe name is if its state is stopped you wont be able to get a connection from Instance pipe name. make sure you have ran SqlLocalDB start <instance name>
image

@benday
Copy link
Author

benday commented Dec 23, 2021

@JRahnama -- Thanks for that input. I hit that named pipe issue you mentioned but did a workaround a while back by simply setting Encrypt=false in the connection string. Not ideal but good enough to allow me to connect via "np:". Put another way, no issues for me on the ARM/Named Pipe thing.

I tried the default instance syntax "(localdb)." that you suggested and I'm still getting the same error. The repro repo that I posted actually ensures that the localdb instance is running before attempting to connect to it.

Per your question about SSMS, SSMS doesn't install on Win11 ARM. But I can connect to localdb using SQL Server Object Explorer in VS2022 running on ARM. What's extra strange is that I can connect to localdb using an app I wrote for dotnet 5 that's published to the store. https://www.microsoft.com/store/productId/9P5DZ9KQC7GR

I think there is something about native .NET6 apps trying to connect that doesn't work from ARM. But that same code works fine when it's run in x86/x64 emulation under ARM.

@JRahnama
Copy link
Contributor

JRahnama commented Jan 5, 2022

@benday is the app on net 5 using same username/password to get connection? If not, I would say you probably need to add user login to your localdb
CREATE LOGIN [username goes here] FROM WINDOWS WITH DEFAULT_DATABASE=[master] and add related roles, but if net5 is working with same credentials that is a different story. Setting up the environment will take sometime.

  1. I created a VM for Windows 11
  2. Added VS2022 and SqlServer 2019
  3. Add a sample repro with ARM64 configuration for net6 TFW

and everything worked as expected. maybe I need to have Windows 11 ARM. Did you try it from Windows 11 Insider Preview Build?

@benday
Copy link
Author

benday commented Jan 5, 2022

@JRahnama --

Yes, you'll definitely need a win11 arm machine to test this. As stated in the original bug report, everything works as expected on win11 on Intel x64. It fails on arm.

Regarding the .net5 app running on win11 arm, I was connecting using "trusted connection=true" and that oddly worked fine.

@JRahnama
Copy link
Contributor

@benday can you try adding AppContext.SetSwitch("Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows", true); in your application to enforce Managed SNI usage to see the behavior?

@JRahnama
Copy link
Contributor

One more question here can you run dumpbin.exe /headers SqlUserInstance.dll in the path of C:\Program Files\Microsoft SQL Server\150\LocalDB\Binn also check Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\15.0 in the registry to see if the path is correctly installed?

@eolamisan
Copy link

eolamisan commented Jan 13, 2022

I am having similar issue with .net 6.0 on regular intel dev laptop connecting to (localdb)\instancename in IIS.

Does not work

(localdb)\instancename

Works

np:\.\pipe\LOCALDB#FA0859AB\tsql\query

Exception

System.Data.Entity.Core.EntityException: The underlying provider failed on Open.
---> System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken)
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.WaitForPendingOpen()
--- End of stack trace from previous location ---
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass4_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.ExecuteAsyncImplementation[TResult](Func1 func) at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter.GetResult() at System.Data.Entity.Core.EntityClient.EntityConnection.OpenAsync(CancellationToken cancellationToken) ClientConnectionId:00000000-0000-0000-0000-000000000000 Error Number:-1,State:0,Class:20 --- End of inner exception stack trace --- at System.Data.Entity.Core.EntityClient.EntityConnection.OpenAsync(CancellationToken cancellationToken) at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter.GetResult() at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnectionAsync(Boolean shouldMonitorTransactions, CancellationToken cancellationToken) at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter.GetResult() at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransactionAsync[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess, CancellationToken cancellationToken)
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.ExecuteAsyncImplementation[TResult](Func1 func) at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter1.GetResult()
at System.Data.Entity.Core.Objects.ObjectQuery1.GetResultsAsync(Nullable1 forMergeOption, IDbExecutionStrategy executionStrategy, CancellationToken cancellationToken)
at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter1.GetResult() at System.Data.Entity.Internal.LazyAsyncEnumerator1.FirstMoveNextAsync(CancellationToken cancellationToken)
at System.Data.Entity.Infrastructure.IDbAsyncEnumerableExtensions.ForEachAsync[T](IDbAsyncEnumerator1 enumerator, Action1 action, CancellationToken cancellationToken)

Configuration

Processor Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz 2.59 GHz
Installed RAM 32.0 GB (31.6 GB usable)
System type 64-bit operating system, x64-based processor

Edition Windows 10 Enterprise
Version 20H2
Installed on ‎12/‎20/‎2020
OS build 19042.1415
Experience Windows Feature Experience Pack 120.2212.3920.0

Should I create a separate ticket?

@eolamisan
Copy link

I am having similar issue with .net 6.0 on regular intel dev laptop connecting to (localdb)\instancename.

Does not work

(localdb)\instancename

Works

np:.\pipe\LOCALDB#FA0859AB\tsql\query

Exception

System.Data.Entity.Core.EntityException: The underlying provider failed on Open.
---> System.Data.SqlClient.SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken)
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.WaitForPendingOpen()
--- End of stack trace from previous location ---
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass4_0.<b__0>d.MoveNext()
--- End of stack trace from previous location ---
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.ExecuteAsyncImplementation[TResult](Func1 func) at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter.GetResult() at System.Data.Entity.Core.EntityClient.EntityConnection.OpenAsync(CancellationToken cancellationToken) ClientConnectionId:00000000-0000-0000-0000-000000000000 Error Number:-1,State:0,Class:20 --- End of inner exception stack trace --- at System.Data.Entity.Core.EntityClient.EntityConnection.OpenAsync(CancellationToken cancellationToken) at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter.GetResult() at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnectionAsync(Boolean shouldMonitorTransactions, CancellationToken cancellationToken) at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter.GetResult() at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransactionAsync[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess, CancellationToken cancellationToken)
at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.ExecuteAsyncImplementation[TResult](Func1 func) at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter1.GetResult()
at System.Data.Entity.Core.Objects.ObjectQuery1.GetResultsAsync(Nullable1 forMergeOption, IDbExecutionStrategy executionStrategy, CancellationToken cancellationToken)
at System.Data.Entity.Utilities.TaskExtensions.CultureAwaiter1.GetResult() at System.Data.Entity.Internal.LazyAsyncEnumerator1.FirstMoveNextAsync(CancellationToken cancellationToken)
at System.Data.Entity.Infrastructure.IDbAsyncEnumerableExtensions.ForEachAsync[T](IDbAsyncEnumerator1 enumerator, Action1 action, CancellationToken cancellationToken)

Configuration

Processor Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz 2.59 GHz Installed RAM 32.0 GB (31.6 GB usable) System type 64-bit operating system, x64-based processor

Edition Windows 10 Enterprise Version 20H2 Installed on ‎12/‎20/‎2020 OS build 19042.1415 Experience Windows Feature Experience Pack 120.2212.3920.0

Should I create a separate ticket?

For some reason setting this flag:

setProfileEnvironment="true"

in this is file:

C:\Windows\System32\inetsrv\config\applicationHost.config

fixed it for me.

Is this the recommended approach?

Source:
https://stackoverflow.com/questions/15491388/iis-applicationhost-setenvironment-attribute

@benday
Copy link
Author

benday commented Jan 14, 2022

One more question here can you run dumpbin.exe /headers SqlUserInstance.dll in the path of C:\Program Files\Microsoft SQL Server\150\LocalDB\Binn also check Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server Local DB\Installed Versions\15.0 in the registry to see if the path is correctly installed?

Here's the output from dumpbin:
dumpbin-output.txt

@benday
Copy link
Author

benday commented Jan 14, 2022

I added a new test to the sample repo that adds that UseManagedNetworkingOnWindows call. The test still fails but it gives a different error message. The new error message is:

System.Exception: Cannot connect to SQL Server Browser. Ensure SQL Server Browser has been started. ---> System.Net.Sockets.SocketException: No such host is known.
Stack Trace:
at System.Net.Dns.GetHostEntryOrAddressesCore(String hostName, Boolean justAddresses, AddressFamily addressFamily, ValueStopwatch stopwatch)
at System.Net.Dns.GetHostAddresses(String hostNameOrAddress, AddressFamily family)
at System.Net.Dns.GetHostAddresses(String hostNameOrAddress)
at System.Net.Sockets.UdpClient.GetEndpoint(String hostname, Int32 port)
at System.Net.Sockets.UdpClient.SendAsync(Byte[] datagram, Int32 bytes, String hostname, Int32 port)
at Microsoft.Data.SqlClient.SNI.SSRP.SendUDPRequest(String browserHostname, Int32 port, Byte[] requestPacket)
at Microsoft.Data.SqlClient.SNI.SSRP.GetPortByInstanceName(String browserHostName, String instanceName)
--- End of inner exception stack trace ---
at Microsoft.Data.SqlClient.SNI.SSRP.GetPortByInstanceName(String browserHostName, String instanceName)
at Microsoft.Data.SqlClient.SNI.SNIProxy.CreateTcpHandle(DataSource details, Int64 timerExpire, Boolean parallel, SqlConnectionIPAddressPreference ipPreference, String cachedFQDN, SQLDNSInfo& pendingDNSInfo)
at Microsoft.Data.SqlClient.SNI.SNIProxy.CreateConnectionHandle(String fullServerName, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Byte[]& instanceName, Byte[][]& spnBuffer, Boolean flushCache, Boolean async, Boolean parallel, Boolean isIntegratedSecurity, SqlConnectionIPAddressPreference ipPreference, String cachedFQDN, SQLDNSInfo& pendingDNSInfo)
at Microsoft.Data.SqlClient.SNI.TdsParserStateObjectManaged.CreatePhysicalSNIHandle(String serverName, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Byte[]& instanceName, Byte[][]& spnBuffer, Boolean flushCache, Boolean async, Boolean parallel, SqlConnectionIPAddressPreference iPAddressPreference, String cachedFQDN, SQLDNSInfo& pendingDNSInfo, Boolean isIntegratedSecurity)
at Microsoft.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover, SqlAuthenticationMethod authType)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, DbConnectionPool pool)
at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection) at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions) at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource1 retry, DbConnectionOptions userOptions)
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 Benday.ArmDemo1.UnitTests.DatabaseConnectionFixture.Connect(String connstr) in c:\code\benday-inc\Benday.ArmDemo1\test\Benday.ArmDemo1.UnitTests\DatabaseConnectionFixture.cs:line 84
at Benday.ArmDemo1.UnitTests.DatabaseConnectionFixture.ConnectToDatabase_ConnectionString_LocalDb_NamedInstance_UseManagedNetworkingOnWindows() in c:\code\benday-inc\Benday.ArmDemo1\test\Benday.ArmDemo1.UnitTests\DatabaseConnectionFixture.cs:line 41

@Xenyr
Copy link

Xenyr commented Jan 18, 2022

Just wanted to report that this issue also concerns a native Windows 11 ARM installation on a Surface Pro X. Yet having troubles to install SQL Server 2019 at all (SQL Server Express, SQL Server Express Advanced and SSMS won't install without errors), the SQL Server 2019 LocalDB installation somehow manages to get through successfully. However, trying to access the local database via connection string (localdb)\MSSQLLocalDB as part of developing a Blazor WASM application gave me exactly the same error as in the original post (provider: SNI_PN11, error: 56 - Unable to load the SQLUserInstance.dll from the location specified in the registry).

Developing using VS Code, I installed the SQL server extension for VS Code (https://docs.microsoft.com/en-us/sql/tools/visual-studio-code/sql-server-develop-use-vscode). Interestingly enough, trying to access the LocalDB via connection string using this extension succeeds on ARM, even starting the database instance if previously stopped. I verified this behaviour calling sqllocaldb info mssqllocaldb before and after accessing the database using the SQL server extension, which gave me an Instance: Stopped with no instance pipe name formerly and an Instance: Running alongside an instance pipe name afterwards.

The Microsoft Surface Pro X has been configurated with a Microsoft SQ2 Processor and 16 GB RAM, running Windows 11 Build 22000.434 on arm64.

@ErikEJ
Copy link
Contributor

ErikEJ commented Jan 18, 2022

@Xenyr I think it should be: (localdb)\MSSQLLocalDB

@Xenyr
Copy link

Xenyr commented Jan 18, 2022

@Xenyr I think it should be: (localdb)\MSSQLLocalDB

Absolutely, sorry for that typo. I had tested it with the backslash back then and therefore edited my comment.

@shwelc2
Copy link

shwelc2 commented Jun 27, 2022

I am experiencing the same issue with Windows 11 Arm/EF 6.06 /Visual Studio 2022 and localDB. I can connect to localdb in SSMS and also visual studio server explorer, but running migrations (update-database) always gives an error about being unable to connect to localdb. I also tried a clean install of the new Visual Studio 2022 Preview (arm) thinking this would resolve it, but the issue is still there.

"DefaultConnection": "Server=(localdb)\mssqllocaldb;Database=aspnet-demo6-53bc9b9d-9d6a-45d4-8429-2a2761773502;Trusted_Connection=True;MultipleActiveResultSets=true"

Error Number:193,State:0,Class:20
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SNI_PN11, error: 56 - Unable to load the SQLUserInstance.dll from the location specified in the registry. Verify that the Local Database Runtime feature of SQL Server Express is properly installed.)

@shwelc2
Copy link

shwelc2 commented Jun 27, 2022

I am experiencing the same issue with Windows 11 Arm/EF 6.06 /Visual Studio 2022 and localDB. I can connect to localdb in SSMS and also visual studio server explorer, but running migrations (update-database) always gives an error about being unable to connect to localdb. I also tried a clean install of the new Visual Studio 2022 Preview (arm) thinking this would resolve it, but the issue is still there.

"DefaultConnection": "Server=(localdb)\mssqllocaldb;Database=aspnet-demo6-53bc9b9d-9d6a-45d4-8429-2a2761773502;Trusted_Connection=True;MultipleActiveResultSets=true"

Error Number:193,State:0,Class:20 A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SNI_PN11, error: 56 - Unable to load the SQLUserInstance.dll from the location specified in the registry. Verify that the Local Database Runtime feature of SQL Server Express is properly installed.)

Should have added also
Edition Windows 11 Enterprise
Version 22H2
Installed on ‎6/‎10/‎2022
OS build 22621.160
Experience Windows Feature Experience Pack 1000.22632.1000.0

@benday
Copy link
Author

benday commented Aug 6, 2022

FYI, I tried re-running my repro repo code (https://github.com/benday-inc/Benday.ArmDemo1) using Visual Studio Enterprise 2022 (ARM 64-bit) Version 17.3.0 Preview 6.0. I'm still getting the same errors.

It would be really nice to be able to work with some kind of SQL Server on ARM64. @JRahnama, are there any updates you could share on this?

Thanks,
-Ben

@JRahnama
Copy link
Contributor

JRahnama commented Aug 7, 2022

@benday MSSQLLocalDb is not supported on Win11 ARM64 so far. The SQLUserInstance.dll is built for x64 and is not compatible for ARM64 and I am not sure who owns that library.

@Sebbs128
Copy link

Sebbs128 commented Nov 3, 2022

Ran into this issue when attempting to debug an ASP.NET 4.8 app on the Windows Dev Kit 2023 yesterday. Given that The VS 2022 ARM64 Preview installs SQL Server 2019 LocalDB as part of the ASP.NET/web development workload, I expected it would be ready.

Curiously, Azure Data Studio connects and runs queries fine (including using the same connection string), and I was able to get a .NET 6 console app to connect and run a query, but only when the build configuration is set to x64 (and not ARM64). The ASP.NET 4.8 still has the same issue when running as x64.

I've created a report in the Visual Studio feedback site, hopefully they're able to determine who owns the library and get it fixed.

@joakimriedel
Copy link

Same here, just bought an Surface Pro 9 SQ3 now that Visual Studio has support for ARM64, but it is not possible to connect to localdb (even though it installs together with supported workload) from NET7/EF7. Azure Data Studio ARM64 can connect successfully so no issue with localdb per se.

@benday
Copy link
Author

benday commented Feb 20, 2023

I was curious if this was fixed under .NET Core 7 so I did an update to the repro repo. https://github.com/benday-inc/Benday.ArmDemo1/tree/update-to-dotnet-7

Answer: nope. Still broken.

@sayitfast
Copy link

I was curious if this was fixed under .NET Core 7 so I did an update to the repro repo. https://github.com/benday-inc/Benday.ArmDemo1/tree/update-to-dotnet-7

Answer: nope. Still broken.

Been broken forever...

@SayHelloGsx
Copy link

I have the same issue. I'm using surface pro x (sq1). Here is my solution to this issue.
Please switch the platform to x64 or x86. Don't use anycpu for your project on ARM64 or you can't use LocalDB.
This is just a temporary solution. I hope SQLUserInstance.dll can support native ARM64.

image

@ghandlin
Copy link

I have the same issue. I'm using surface pro x (sq1). Here is my solution to this issue. Please switch the platform to x64 or x86. Don't use anycpu for your project on ARM64 or you can't use LocalDB. This is just a temporary solution. I hope SQLUserInstance.dll can support native ARM64.

image

I'm using a Mac and don't have the option for x86 or x64 ... did you create a new configuration or does VS show those on the Surface?

@SayHelloGsx
Copy link

I have the same issue. I'm using surface pro x (sq1). Here is my solution to this issue. Please switch the platform to x64 or x86. Don't use anycpu for your project on ARM64 or you can't use LocalDB. This is just a temporary solution. I hope SQLUserInstance.dll can support native ARM64.
image

I'm using a Mac and don't have the option for x86 or x64 ... did you create a new configuration or does VS show those on the Surface?

Yes, I created a new configuration. You need to clieck "Any CPU", then click "Configuration Manager" -> click "Any CPU" -> "New". You will find all supported CPU platforms. Select x64 or x86, then click "OK"

@jbogard
Copy link

jbogard commented Jun 16, 2023

Weirdly enough I've got an old app running RoundhousE, a database migration tool built against .NET 4.5 and uses some version of System.Data.dll. It's able to run migrations and populate the DB just fine. The app doesn't run with EF6 against SQL Local DB however, gets this error.

@Meligy
Copy link

Meligy commented Apr 19, 2024

I second @jbogard findings. I had a .NET Framework app (.NET Framework 4.8) that worked just fine with Local DB, then after migrating it to .NET Core (.NET 8 actually), it started showing errors about connecting. Same connection string and everything.

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 56 - Unable to load the SQLUserInstance.dll from the location specified in the registry. Verify that the Local Database Runtime feature of SQL Server Express is properly installed.)

@danieltharris
Copy link

Are there plans to remedy this?

I have the same issue. I'm using surface pro x (sq1). Here is my solution to this issue. Please switch the platform to x64 or x86. Don't use anycpu for your project on ARM64 or you can't use LocalDB. This is just a temporary solution. I hope SQLUserInstance.dll can support native ARM64.
image

I'm using a Mac and don't have the option for x86 or x64 ... did you create a new configuration or does VS show those on the Surface?

LocalDB isn't available for Mac - Are you running Local DB in Parallels and connecting to it from the Mac? On Mac an alternative that's worked for me is to run SQL Edge in Docker, works well for development purposes on my M3 Pro MBP (and was also fine on M1 MBA and M1 Pro MBP in the past)

@danieltharris
Copy link

@JRahnama is a fix for this issue planned or will localdb remain unsupported on Windows on ARM devices? It would be useful to have this available to avoid having to run alternatives such as SQL Edge in Docker - Especially since the rest of the modern .NET toolchain is now ARM Native (I think Azure functions are still an issue, but web and mobile has been a great experience so far)

@shwelc2
Copy link

shwelc2 commented Aug 21, 2024

I got around this on my Mac Windows/Arm VM just using these alternative install scripts. The SQL express or any of the normal modern SQL servers run fine for me, I didn't try the native localdb but it may work also. You can just install the SQL server developer version and it should work.

https://github.com/jimm98y/MSSQLEXPRESS-M1-Install

I also did this as well prior so enable visual studio to connect using the arm64 dll for sql client.

  1. Downloading the Microsoft.Data.SqlClient.SNI package in NuGet.

  2. Copying Microsoft.Data.SqlClient.SNI.arm64.dll within build\net462 into C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\Extensions\Microsoft\SQLDB\DAC (ensuring the version I copied across matched the version reported by Microsoft.Data.SqlClient.SNI.x64.dll).

  3. Restarting Visual Studio and testing connections.
    Upon restart, this enabled connections to my SQL Server Express instance running on the host within a Docker container. It seems to work for me (so far!) so I'm hoping it does for you too.

@LouisGordon
Copy link

I worked around the issue by creating a SQL alias for the localdb named pipes connection and keeping that up to date (with the latest named pipes value for the localdb instance) via a scheduled task. Then your connection string server becomes LocalDbAlias, which is good enough for me.

https://dev.to/louisgordon/localdb-dev-on-windows11-arm-cm3

@jbogard
Copy link

jbogard commented Aug 21, 2024

I got around this on my Mac Windows/Arm VM just using these alternative install scripts. The SQL express or any of the normal modern SQL servers run fine for me, I didn't try the native localdb but it may work also. You can just install the SQL server developer version and it should work.

https://github.com/jimm98y/MSSQLEXPRESS-M1-Install

I also did this as well prior so enable visual studio to connect using the arm64 dll for sql client.

  1. Downloading the Microsoft.Data.SqlClient.SNI package in NuGet.
  2. Copying Microsoft.Data.SqlClient.SNI.arm64.dll within build\net462 into C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\Extensions\Microsoft\SQLDB\DAC (ensuring the version I copied across matched the version reported by Microsoft.Data.SqlClient.SNI.x64.dll).
  3. Restarting Visual Studio and testing connections.
    Upon restart, this enabled connections to my SQL Server Express instance running on the host within a Docker container. It seems to work for me (so far!) so I'm hoping it does for you too.

Just an FYI, I went this route as well to get "normal" SQL working, but it doesn't work for SQL Local DB. Unfortunately.

@michelemottini
Copy link

I am having the same issue - using Microsoft Surface Pro 11 with Windows 11. I have been able to work around it building as x64 but cannot see LocalDB from Visual Studio itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

17 participants