-2

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.

  • Please add more details. A screenshot about the error message would be nice start. – vonPryz Jul 28 '16 at 7:49
  • @vonPryz No, a screenshot would not be a nice start, but copy/paste of the error message text would. Screenshots are bad because they are not searcheable. – mustaccio Jul 28 '16 at 15:21
  • @mustaccio Please see the original question why a screenshot was asked for. As a side note, quite a few Windows' dialogs actually support ctrl+c for copying the text content. – vonPryz Jul 29 '16 at 5:44
2

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.

  • On what assumption you base this guess? Maybe user is out of disk space, lacks permissions, has syntax error in command (this is unlikely, more like wrong GUI settings I'd say), is trying to restore log instead of database and so on. – vonPryz Jul 28 '16 at 7:57
  • On the basis user states error as being 'database already in use'. Suggests connections open, which is a common restore failure. My answer states the likely issue with a potential solution based on the information provided. – Molenpad Jul 28 '16 at 8:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.