I have trouble to restore SQL Server 2008 database. I receive an error message when I try to restore that restore failed and database is already in use. I try to restore backup from my D drive. Why I receive this error?
closed as unclear what you're asking by Philᵀᴹ, Shanky, Michael Green, dezso, Vérace Jul 28 '16 at 18:29
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
Likely your database (the one your are attempting to restore/replace) currently has open connections.
Try this logic:
ALTER DATABASE <yourdatabase> SET SINGLE_USER WITH ROLLBACK IMMEDIATE; RESTORE DATABASE <yourdatabase> FROM DISK = "D:\Backups\BackupFile.Bak" WITH REPLACE, RECOVERY; ALTER DATABASE <yourdatabase> SET MULTI_USER;
Setting the database to single user mode will close/rollback any existing connections except the current session
Set it back to multi user afterwards to return it to normal.