So the localdb instance works, but the connection from .NET does not. And, well, it says Unable to load the SQLUserInstance.dll from the location specified in the registry. So that suggests that something is broken on those machines. I don't know the gory details here, but maybe you should make comparisons between the file system and the registry between a broken machine and a healthy one. Maybe the registry has been tampered with. Maybe the file is missing from disk?
Error when attempting to use SQL 2016 LocalDb on Win 10 workstation
My customer is attempting to use SQL 2016 LocalDB by installing the .msi file and then connecting through entity frameworks. This solution works fine on all but four of his workstations. On the workstations that are functioning correctly, he can connect to (LocalDb)\MSSQLLocalDB using SSMS. When attempting to connect on these four workstations, he receives the error below. We've tried disabling antivirus and another tool that we thought might interfere. Can anyone provide some guidance?
“Error occurred when attempting to start a result processing session. Additional error details: System.InvalidOperationException: This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection. ---> System.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: 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.) ---> System.ComponentModel.Win32Exception: %1 is not a valid Win32 application”.
What happens if they open a command-line window on these machines and run
sqllocaldb start mssqllocaldb
If this prints
LocalDB instance "MSSQLLocalDB" started.
What happens if they run
SQLCMD -S (localdb)\MSSQLLocalDB
Both commands run fine. When the SQLCMD... command is run, I see a prompt with a numbered line like this: 1>
Subsequent commands like listing the databases, selecting GetDate(), etc., all work fine. However, still cannot connect to it using VS with EF or SSMS.
Sign in to comment
Sort by: Most helpful
Thanks Erland. That was my thought as well. I've asked the team to compare things like group policies between a good and a bad machine.
Sign in to comment
I found a similar thread, maybe you can use it as a reference: https://learn.microsoft.com/en-us/answers/questions/465081/i-tried-to-connect-to-localdb-with-vs-2019-and-i-c.
For more information about SQL Server Express LocalDB, you can check this link; https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-express-localdb?view=sql-server-ver16.