2

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?

tereško
  • 58,060
  • 25
  • 98
  • 150
Dinesh
  • 21
  • 1
  • 3
  • 1
    Your connection string shows a `.sdf` file (SQL Server **Compact Edition**) being referenced - just a typo ?? So what do you **really** want - attach an `.mdf` (SQL Server - full version) or use SQL Server **CE** (with a `.sdf` file)?? – marc_s Jan 21 '15 at 19:10

1 Answers1

3

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