I attempted to copy a database, using Microsoft SQL Server Management Studio (SSMS), but right-clicking and following the wizard. I wanted to target server to be the same as the source, so I added "_new" to the database name.
The process failed (unfortunately I missed the error message) and now the source database is missing as well. I found another post on the same topic, which suggests locating and atttaching the .mdf file.
However, when I try to attach the mdf file, I get the following error meesage:
Failed to retrieve data for this request. (Microsoft.SqlServer.Management.Sdk.Sfc)
Luckily this was just a test database, so I didn't lose any data, that couldn't be easily reproduced. But is there a way to recover from this? If it ever happened on a production database, I would like to be prepared.
Best Answer
If the database is no longer listed on the instance, but you can still see the .mdf file, it somehow got detached during this first unsuccessful attempt. The screenshot error says:
The error is related to security and Microsoft states something about security changes during the process of detaching or attaching a database:
In order to fix it, check the permissions of the
.mdf
file and if you confirm it has really been changed, alter them to allow you to execute the attach procedure or run the attach procedure with the same login that is now the owner of the.mdf
file.DANIEL HUTMACHER described this behaviour very well in his article Detaching a database also alters file permissions and his conclusions are: