EntityFramework - Cannot attach the file as database

Problem

In one of the project I was using LocalDB and EntityFramework's Code First approach.

I manually deleted files from App_Data folder, and the next time I started the application or tried to execute update-database command, I got an error message saying 'Cannot attach the file NNN as database NNN'.

Solution

To fix the error, open the Package Manager Console in Visual Studio and run the following commands:

sqllocaldb.exe stop v11.0

sqllocaldb.exe delete v11.0

update-database

comments powered by Disqus