EF5: Cannot attach the file ‘{0}#39; as database #39;{1}#39;(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.
- 在开始/程序菜单下打开VisualStudio 开发人员命令提示符".
运行以下命令:
- Open the "Developer Command Propmpt for VisualStudio" under your start/programs menu.
Run the following commands:
sqllocaldb.exe 停止 v11.0
sqllocaldb.exe 删除 v11.0
这篇关于EF5:无法附加文件“{0}"作为数据库“{1}"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:EF5:无法附加文件“{0}"作为数据库“{1}"


- 导入具有可变标题的 Excel 文件 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01