Search code examples
c#sqlasp.netlocaldb

Unable to connect to LocalDB from ASP.NET Core


I'm trying to setup a database for my ASP.NET Core Web Application. Unfortunately each time I try to run dotnet ef Database Update, I get this error:

Error Number:-1983577829,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: 50 - Local Database Runtime err
or occurred. Specified LocalDB instance name is invalid.)

I've tried everything I can think of, and have reinstalled multiple times. I've installed Visual Studio 2019 with LocalDB, 2022 with LocalDB, LocalDB by itself, SQLExpress with LocalDB, and it all has not worked. I've even reset my PC, which unfortunately has still not changed anything.

Here is my connection string:

"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=PROJECT_NAME_HERE;Trusted_Connection=True;MultipleActiveResultSets=true"

And I am utilizing the connection string with this:

services.AddDbContext<ApplicationDbContext>(options =>
 {
     options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection"));
 });

I should mention that this connection string has worked in the past. Any help would be appreciated! Thanks :D


Solution

  • After more and more Googling and researching, I found someone on Reddit that is having a very similar issue, with the same error message through the Event Viewer. The common ground between us is Windows 11, we've both exhausted all of our options.

    I thought it might have been because I was on Windows 11, but I thought the chances of that were very minor. I guess it is though. My apologies!

    Tl;dr: The assumption is that Windows 11 is not working properly with the SQL Installations.