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.)
An instance of SQL Server Express LocalDB is an instance created by a user for their use. Any user on the computer can create a database using an instance of LocalDB, store files under their user profile, and run the process under their credentials. By default, access to the instance of LocalDB is limited to its owner.
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" 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With