I'm working with a bunch of *.mdf files which I'm attaching on my local computer. After I accidentally deleted the a folder containing some of the *.mdf files, I'm unable to view the databases in SQL Management Studio, and therefore can't detach them.
When opening SQLMS I'm getting the error:
Unable to open the physical file "D:\Foo\bar.mdf".
Operating error 5: "5(Access is denied)". (Microsoft SQL Server, Error: 5120)
I have backups of the files, and even if I restore the files, I still get this error.
After restoring the file to the original path, I'm trying to re-attach the database from file, but get the error:
Cannot attach a database with the same name as an existing database.
But I can't see the previous database either, so I can't detach it.
How do I detach/remove/delete the old database so I can re-attach it from file?