"Cannot attach the file" error when deleting a database from the App_Data folder with LocalDb in MVC?

Exitos

I am using LocalDb and I just want to delete my database.

I was under the impression that due to the way that LocalDb works I would just be able to access the *.mdf and *.ldf files that the local DB instance has created in my App_Data folder (I am using MVC5 by the way).

And that next time I start the application and use it they would just create new files and I would have a new database. But when I delete the files I get the following message...

Cannot attach the file 'c:\users\exitos\documents\visual studio 2013\Projects\xxxxxxxxxxxxxxxxxxxxxx\xxxxxxxxxxxxxxxxxxxxxx\App_Data\aspnet-xxxxxxxxxxxxxxxxxxxxxx-20140118101721.mdf' as database 'aspnet-xxxxxxxxxxxxxxxxxxxxxx-20140118101721'.

Why? I did a reset to my initial commit using GIT to make sure the entire solution folder was 'box fresh' and I still get the problem. I even stopped the Sql Server Express from running and killed all Sql processes and still the same problem.

Is the .ldf and .mdf file written to the registry or something?

I changed the name of the file in the .config and it worked but I don't want to have to keep doing that. I just want to tear down my database by physically deleting it...

hutchonoid

This is not obvious but it is advised that you should not delete the physical .mdf and .log files outside of the SQL Server Object Explorer in Visual Studio or in SQL Server Management Studio.

If this happens you can un-register it by using the object explorer.

Go to Server Explorer > data connections, find the db and delete it from there.

enter image description here

Visual studio will then re-create the db next time without an issue.

I learnt about this from a video by Scott Allen but he's also documented it here.

http://odetocode.com/blogs/scott/archive/2012/08/15/a-troubleshooting-guide-for-entity-framework-connections-amp-migrations.aspx

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

"Cannot attach the file as database" error when installing my Code First ClickOnce app

From Dev

"Cannot attach the file as database" error when installing my Code First ClickOnce app

From Java

Cannot attach the file *.mdf as database

From Dev

Cannot attach the file ".mdf" as database "aspnet-"

From Dev

SQL logic error or missing database no such table when deleting from database

From Dev

Cannot attach the file as database / The underlying provider failed on Open

From Dev

Cannot attach the file as database / The underlying provider failed on Open

From Dev

Cannot attach the file *.mdf as database in asp.net

From Dev

App_Data folder not available in an MVC 5 project VS 2017

From Dev

SqlDependency.Start() gives error Cannot attach the file 'C:\Program Files (x86)\IIS Express\EduTech.mdf' as database 'EduTech'

From Dev

What does THIS code do when deleting data from the database?

From Dev

Issues when deleting data in database

From Dev

Issues when deleting data in database

From Dev

Deleting data from sqlite database

From Dev

how to save the data from database to a folder in mvc application

From Dev

How can I write data to the App_Data folder in ASP.NET MVC?

From Dev

Deleting database records MVC

From Dev

how to allow download access to specific folder only in App_Data asp.net mvc

From Dev

Entity Framework Error. The underlying provider failed on Open Cannot attach the file

From Dev

Error when deleting item from tableview in swift

From Dev

Error when Deleting Node from BST

From Dev

Error when getting data from a SQLite database

From Dev

Webdeploy - precompile asp.net application error with excluded connectionstrings in excluded app_data folder

From Dev

Objectively deleting data from Oracle database

From Dev

Deleting data from SQLite Database is not working

From Dev

deleting data from database with jsp page

From Dev

App_Data folder shadow folder empty

From Dev

How can I prevent TFS from locking binary files in the App_Data folder?

From Dev

How to transfer ASP.NET MVC Database from LocalDb to SQL Server?

Related Related

  1. 1

    "Cannot attach the file as database" error when installing my Code First ClickOnce app

  2. 2

    "Cannot attach the file as database" error when installing my Code First ClickOnce app

  3. 3

    Cannot attach the file *.mdf as database

  4. 4

    Cannot attach the file ".mdf" as database "aspnet-"

  5. 5

    SQL logic error or missing database no such table when deleting from database

  6. 6

    Cannot attach the file as database / The underlying provider failed on Open

  7. 7

    Cannot attach the file as database / The underlying provider failed on Open

  8. 8

    Cannot attach the file *.mdf as database in asp.net

  9. 9

    App_Data folder not available in an MVC 5 project VS 2017

  10. 10

    SqlDependency.Start() gives error Cannot attach the file 'C:\Program Files (x86)\IIS Express\EduTech.mdf' as database 'EduTech'

  11. 11

    What does THIS code do when deleting data from the database?

  12. 12

    Issues when deleting data in database

  13. 13

    Issues when deleting data in database

  14. 14

    Deleting data from sqlite database

  15. 15

    how to save the data from database to a folder in mvc application

  16. 16

    How can I write data to the App_Data folder in ASP.NET MVC?

  17. 17

    Deleting database records MVC

  18. 18

    how to allow download access to specific folder only in App_Data asp.net mvc

  19. 19

    Entity Framework Error. The underlying provider failed on Open Cannot attach the file

  20. 20

    Error when deleting item from tableview in swift

  21. 21

    Error when Deleting Node from BST

  22. 22

    Error when getting data from a SQLite database

  23. 23

    Webdeploy - precompile asp.net application error with excluded connectionstrings in excluded app_data folder

  24. 24

    Objectively deleting data from Oracle database

  25. 25

    Deleting data from SQLite Database is not working

  26. 26

    deleting data from database with jsp page

  27. 27

    App_Data folder shadow folder empty

  28. 28

    How can I prevent TFS from locking binary files in the App_Data folder?

  29. 29

    How to transfer ASP.NET MVC Database from LocalDb to SQL Server?

HotTag

Archive