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}"
基础教程推荐
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 无法解决整理冲突 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
