The specified LocalDb instance does not exist

2019-01-23 05:54发布

I've been using a localDB named 'Projects' for a while now. This is the same database that is created by default ASP.NET MVC 5 project. However, suddenly it stopped and I'm not able to connect to it nor restart it using

SqlLocalDb start Projects

I get

The specified LocalDB instance does not exist.

I see the folder in

C:\Users\[My UserName]\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\Projects

also, I have v11.0 in

C:\Users\[My UserName]\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\v11.0

I'm able to connect to v11.

What else can I try to reconnect to it?

The connection string is

 <add name="DefaultConnection"  connectionString="Data Source=(localdb)\Projects;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False" providerName="System.Data.SqlClient" />

Edit

I tried Attaching the Db file to the connection string

AttachDbFileName=C:\Users\[My UserName]\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\Projects\master.mdf;

However, I'm still not able to connect

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. The specified LocalDB instance
does not exist.)

4条回答
劳资没心,怎么记你
2楼-- · 2019-01-23 06:41

Seems like (localdb)\Projects instance got deleted. You can either use (localdb)\v11.0 or recreate Projects instance using SqlLocalDB utility

sqllocaldb c Projects 11.0

Command line explained

  • c - is for "create"
  • "Projects - is the instance name
  • 11.0 is the version
查看更多
成全新的幸福
3楼-- · 2019-01-23 06:41

Interesting that I just experienced the same problem after using (LocalDb)\Projects just fine for months.

I happen to know the last thing I did on my machine before it stopped working was to install an updated version of Telerik's Kendo MVC UI (which also happens to install a KENDO.MVC.EXAMPLES\APP_DATA\SAMPLE.MDF in LocalDb v11.0) and I'll bet starts and stops the v11.0 local db which screws the Projects instance up somehow and just like you nothing restarts it.

However if you copy all your .mdf and .ldf files into a temporary folder FIRST, and THEN follow Mrchief's advice to create the "Projects" instance again, and THEN copy your files back over top of the files the create puts in the Projects, it will restore your Projects db back to its original state.

Just did it one second ago and it worked.

查看更多
走好不送
4楼-- · 2019-01-23 06:49

In my case the Projects instance was already there, actually after invoking this in the command line:

sqllocaldb i

A list of all the instances shows up, mine were:

  • MSSQLLocalDB
  • Projects
  • ProjectsV12
  • v11.0

The connection string in my Web.Config had Data Source=(LocalDb)\v11.0 by default, so I supposed the instance should actually be v11.0 and not Projects. By executing sqllocaldb i v11.0:

Name: v11.0

Version: 11.0.3000.0

...

Auto-create: Yes

State: Stopped

...

And by starting the instance with sqllocaldb s v11.0 the State was changed to Running, but even while these instances were all running, the exception was still being thrown.

I figured out later that the name of the instance must be the one that shows up when you invoke Update-Database -Verbose in the Package Manager Console, in mine this showed up:

Target database is: 'Videos.Models.VideoDb' (DataSource: (localdb)**v12.0**, Provider: System.Data.SqlClient, Origin: Convention).

Therefore I just needed to create v12.0 instance with sqllocaldb c v12.0 12.0 and adjust the Web.Config to this name. After doing this the update was successful.

查看更多
戒情不戒烟
5楼-- · 2019-01-23 06:50

you can change the attribute --> parameter to "v11.0" instead of v12.0 in the entityFramework tags in the web.config or App.config it works good

查看更多
登录 后发表回答