ERROR MESAGGE:
“Exclusive access could not be obtained because the database is in use.”
EXPLANATION:
You can get this error because you can’t put an exclusive lock on the database because there are other sessions that use the database when you try to restore a database.
SOLUTION:
You can perform operations after killing active sessions in database.
Or you can perform this operation with the help of the following script. Note that this script will kill all sessions in the database.
1 2 3 4 5 |
USE master GO ALTER DATABASE MyDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO RESTORE DATABASE MyDB.... |