无法将文件.mdf附加为数据库 [英] Cannot attach the file .mdf as database

查看:117
本文介绍了无法将文件.mdf附加为数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在尝试获得一个MVC技术,而不是使用实体框架,从SQL Server Compact数据库记录,但错误发生在 EmployeeController 类中步骤:

  Employee employee = empContext.Emp.Single(x => x.EmployeeID == id); 

错误消息:


无法将文件'E:\DotNet\MVC4Application\MVC4Application\App_Data\MVC4Application.Models.EmployeeContext.mdf'附加为数据库'MVC4Application.Models.EmployeeContext'。



异常详细信息:System.Data.SqlClient.SqlException:无法将文件'E:\DotNet\MVC4Application\MVC4Application\App_Data\MVC4Application.Models.EmployeeContext.mdf'附加为数据库'MVC4Application.Models.EmployeeContext'。


连接字符串:

 <&的ConnectionStrings GT; 
< add name =EmployeeContext
connectionString =Data Source = E:\DotNet\MVC4Application\MVC4Application\App_Data\Database1.sdf; Persist Security Info = False/> ;
< / connectionStrings>

请问有人能帮我解决这个错误信息吗?

解决方案

您可以尝试以下(一个一个):




  • 删除数据库在SSMS中

  • 杀死IIS

  • 通过包管理器控制台运行以下命令:

      sqllocaldb.exe停止v11.0(或12.0?)
    sqllocaldb.exe删除v11.0



I'm new to MVC technology, going though a training material and struck up with below error message with Entity Framework.

Here I'm trying to get one record from SQL Server Compact database but error occurs in EmployeeController class at step:

Employee employee = empContext.Emp.Single(x => x.EmployeeID == id);

Error message:

Cannot attach the file 'E:\DotNet\MVC4Application\MVC4Application\App_Data\MVC4Application.Models.EmployeeContext.mdf' as database 'MVC4Application.Models.EmployeeContext'.

Exception Details: System.Data.SqlClient.SqlException: Cannot attach the file 'E:\DotNet\MVC4Application\MVC4Application\App_Data\MVC4Application.Models.EmployeeContext.mdf' as database 'MVC4Application.Models.EmployeeContext'.

Connection string:

<connectionStrings>
    <add name="EmployeeContext" 
         connectionString="Data Source=E:\DotNet\MVC4Application\MVC4Application\App_Data\Database1.sdf;Persist Security Info=False"/>
</connectionStrings>

Could someone help me with this error message, please?

解决方案

You can try the following (one by one):

  • Deleting DB in SSMS
  • Kill IIS
  • Run the following commands via the package manager console:

    sqllocaldb.exe stop v11.0 (or 12.0?) 
    sqllocaldb.exe delete v11.0
    

这篇关于无法将文件.mdf附加为数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆