asp.net-mvc 指定的 LocalDb 实例不存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26007913/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The specified LocalDb instance does not exist
提问by Roman Mik
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
我一直在使用名为“Projects”的 localDB 一段时间了。这与默认 ASP.NET MVC 5 项目创建的数据库相同。但是,突然它停止了,我无法连接到它,也无法使用它重新启动它
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
另外,我有 v11.0
C:\Users\[My UserName]\AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\v11.0
I'm able to connect to v11.
我可以连接到 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
我尝试将 Db 文件附加到连接字符串
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.)
回答by Mrchief
Seems like (localdb)\Projectsinstance got deleted. You can either use (localdb)\v11.0or recreate Projectsinstance using SqlLocalDB utility
好像(localdb)\Projects实例被删除了。您可以使用SqlLocalDB 实用程序使用(localdb)\v11.0或重新创建Projects实例
sqllocaldb c Projects 11.0
Command line explained
命令行解释
c- is for "create"- "Projects - is the instance name
- 11.0 is the version
c- 用于“创建”- “项目 - 是实例名称
- 11.0是版本
回答by CPHPython
In my case the Projectsinstance was already there, actually after invoking this in the command line:
在我的情况下,Projects实例已经存在,实际上是在命令行中调用它之后:
sqllocaldb i
A list of all the instances shows up, mine were:
出现了所有实例的列表,我的是:
- MSSQLLocalDB
- Projects
- ProjectsV12
- v11.0
- 本地数据库
- 项目
- 项目V12
- v11.0
The connection string in my Web.Confighad Data Source=(LocalDb)\v11.0by default, so I supposed the instance should actually be v11.0and not Projects. By executing sqllocaldb i v11.0:
默认情况下,我的Web.Config 中的连接字符串具有Data Source=(LocalDb)\v11.0,因此我认为该实例实际上应该是v11.0而不是Projects。通过执行sqllocaldb i v11.0:
Name: v11.0
Version: 11.0.3000.0
...
Auto-create: Yes
State: Stopped
...
名称: v11.0
版本:11.0.3000.0
...
自动创建:是
状态:停止
...
And by starting the instance with sqllocaldb s v11.0the Statewas changed to Running, but even while these instances were all running, the exception was still being thrown.
并且通过sqllocaldb s v11.0将State更改为Running来启动实例,但是即使这些实例都在运行,异常仍然被抛出。
I figured out later that the name of the instance must be the one that shows up when you invokeUpdate-Database -Verbosein the Package Manager Console, in mine this showed up:
后来我发现实例的名称必须是您Update-Database -Verbose在Package Manager Console 中调用时显示的名称,在我的中显示为:
Target database is: 'Videos.Models.VideoDb' (DataSource: (localdb)**v12.0**, Provider: System.Data.SqlClient, Origin: Convention).
目标数据库是:'Videos.Models.VideoDb'(数据源:(localdb)**v12.0**,提供者:System.Data.SqlClient,来源:约定)。
Therefore I just needed to create v12.0instance with sqllocaldb c v12.0 12.0and adjust the Web.Configto this name. After doing this the update was successful.
因此,我只需要使用此名称创建v12.0实例sqllocaldb c v12.0 12.0并将Web.Config调整为该名称。执行此操作后,更新成功。
回答by bkimpel
Interesting that I just experienced the same problem after using (LocalDb)\Projects just fine for months.
有趣的是,我在使用 (LocalDb)\Projects 几个月后刚刚遇到了同样的问题。
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.
我碰巧知道我在机器停止工作之前在我的机器上做的最后一件事是安装 Telerik 的 Kendo MVC UI 的更新版本(它也恰好在 LocalDb v11.0 中安装了 KENDO.MVC.EXAMPLES\APP_DATA\SAMPLE.MDF ) 并且我敢打赌启动和停止 v11.0 本地数据库,它以某种方式将 Projects 实例搞砸了,就像你一样,没有什么会重新启动它。
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.
但是,如果您首先将所有 .mdf 和 .ldf 文件复制到临时文件夹中,然后按照 Mrchief 的建议再次创建“项目”实例,然后将您的文件复制回创建放在项目中的文件的顶部,它会将您的项目数据库恢复到其原始状态。
Just did it one second ago and it worked.
一秒钟前刚刚做了,它奏效了。
回答by venkata
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
您可以在 web.config 或 App.config 中的 entityFramework 标签中将属性 --> 参数更改为“v11.0”而不是 v12.0 效果很好

