I am building a web application using VS 2012 MVC4 code first. In order to recreate the .mdf file after I changed the model, I manually deleted the file from th
Try deleting it again from SQL Management Studio. It'll complain that there's no physical file any more but will remove from the object browser (You'll see after you refresh it)
Use SQL Server Object Explorer to delete the database rather than just deleting the .mdf file in Solution Explorer. Otherwise the SQL Server instance still thinks the database name is used and the next time you try to attach a database to the same name it won't work. See the section on Initial Catalog in this MSDN page:
http://msdn.microsoft.com/en-us/library/jj653752.aspx#initialcatalog
exit localhost iis express and try again.
I delete my DBContext class and re created it again in my MVC Project. Then .mdf file is re created in App_Data
Remove this line from the connection string that should work ;)
"AttachDbFilename=|DataDirectory|whateverdatabasename-20130917064511.mdf"
That what fixed it for me, From Package Manager Console run these commands:
sqllocaldb.exe stop v11.0
sqllocaldb.exe delete v11.0
And then:
Update-Database