0

I am writing a .NET Core 2.1 web API using MS LocalDB. I can connect to my DB fine using SSMS and the server name (localdb)\MSSQLLocalDB with Windows Authentication.

The API fails to connect with the error:

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: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.

My connection string is:

Server=(localdb)\\MSSQLLocalDB;Database=Foo;Trusted_Connection=True;MultipleActiveResultSets=true

As a side note, I tried to check my LocalDB version with sqllocaldb v but got the following error:

Windows API call "RegGetValueW" returned error code: 0.

Is my LocalDB installation completely borked?

TylerH
  • 20,799
  • 66
  • 75
  • 101
user3352488
  • 281
  • 3
  • 15
  • You might have to change the instance name. Check out this question: https://stackoverflow.com/questions/26248293/sql-network-interfaces-error-50-local-database-runtime-error-occurred-canno – Kristóf Tóth Mar 20 '19 at 10:49
  • I can't find anything about renaming an instance there. However, I have tried creating a brand new instance and now get a different exception: provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot get a local application data path. Most probably a user profile is not loaded. If LocalDB is executed under IIS, make sure that profile loading is enabled for the current user. – user3352488 Mar 20 '19 at 11:00
  • https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/sql-server-2016-express-localdb?view=sql-server-2017 – Kristóf Tóth Mar 20 '19 at 11:03
  • I've had to give up for now and switch to a remote SQL box. – user3352488 Mar 20 '19 at 11:43

1 Answers1

1

its kinda late but i am trying this for 2 days and finally found the answer.

  1. When app is running on IIS --> go to advance setting in the application pool, then on change "Process Model->Load Profile" to TRUE;

  2. when app is running on Kestrel, a. connection string "Data Source=(localdb)\mssqllocaldb"... etc

hope this help the others.

gio
  • 11
  • 1