MSSQL: Database * already exists. Choose a different database name. Cannot attach the file * as database.

I am currently playing around with ASP.NET and its Entity Framework. At some point I wanted to execute all my migrations against a new local SQL Express database. After I had dropped the database in SQL Management Studio, the Update-Database command of the Entity Framework failed with the error “Database ‘$path.mdf’ already exists. Choose a different database name. Cannot attach the file ‘$path.mdf’ as database” (German translation: “Die ‘$path.mdf’-Datenbank ist bereits vorhanden. Wählen Sie einen anderen Datenbanknamen aus. Die Datei ‘$path.mdf’ kann nicht als ‘$path’-Datenbank angefügt werden.”).

SQL Server Management Studio did not longer show the database as present. A manually executed DROP DATABASE SQL statement only showed that there was not such a database. After checking some other possible error sources (machine.config, web.config and so on), I ended up with downloading sseutil from and dropped the database by hand:

> sseutil -s \.SQLEXPRESS -l # shows all databases in the local SQL Express instance
1. master
2. tempdb
3. model
4. msdb
5. $failed_database

> sseutil -s \.SQLEXPRESS -d name=$failed_database
Failed to detach '$failed_database'

Although I received the detachment error, the database was no longer registered and I was able to execute the Update-Database statement without any problems