EF5:无法附加文件“{0}"作为数据库“{1}"

EF5: Cannot attach the file ‘{0}#39; as database #39;{1}#39;(EF5:无法附加文件“{0}作为数据库“{1})
本文介绍了EF5:无法附加文件“{0}"作为数据库“{1}"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了上述的确切问题 这里(阅读无法附加到已删除的MDF文件"部分),但那里没有告诉问题的解决方案...

I'm encountering the exact issue as described here (read section "Cannot Attach to Deleted MDF File"), but the solution to the problem is not told there...

简而言之,问题是删除 .mdf 文件后,当我尝试使用 EF 5.0 访问数据库时抛出以下异常.

In short the issue is that after deleting the .mdf file, the following exception is thrown when I try to access the DB using EF 5.0.

DataException->EntityException->SqlException:
无法附加文件{0}"作为数据库{1}"

DataException->EntityException->SqlException:
Cannot attach the file ‘{0}' as database '{1}'

我确实删除了 DB 文件,现在我在运行应用程序时收到了令人讨厌的错误消息,希望它使用它的初始化程序.有什么办法可以解决这个问题?

I did delete the DB file and now I get that nasty error message when running the application expecting it to use it's initializer. Any way to fix this?

推荐答案

如果删除 DB 文件,它仍会在 SqlLocalDB 中保持注册状态.有时它会修复它以删除数据库.您可以从命令行执行此操作.

If you delete the DB file, it still stays registered with SqlLocalDB. Sometimes it fixes it to delete the DB. You can do this from the command line.

  1. 在开始/程序菜单下打开VisualStudio 开发人员命令提示符".
  2. 运行以下命令:

  1. Open the "Developer Command Propmpt for VisualStudio" under your start/programs menu.
  2. Run the following commands:

sqllocaldb.exe 停止 v11.0

sqllocaldb.exe 删除 v11.0

这篇关于EF5:无法附加文件“{0}"作为数据库“{1}"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)