The specified LocalDb instance does not exist

前端 未结 4 1458
花落未央
花落未央 2020-12-15 07:53

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

相关标签:
4条回答
  • 2020-12-15 08:24

    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

    0 讨论(0)
  • 2020-12-15 08:27

    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.

    0 讨论(0)
  • 2020-12-15 08:45

    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.

    0 讨论(0)
  • 2020-12-15 08:49

    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
    0 讨论(0)
提交回复
热议问题