I am encountering the following error during the automatic restoration of my database: “ERROR: Failed to restore database. One or more errors occurred. > Unable to obtain exclusive access because the database is currently in use. RESTORE DATABASE terminated abnormally.”
Is it possible to add an SQL instruction to terminate all active sessions on the database and set it to “SINGLE_USER” mode before starting the restoration, then switch it back to “MULTI_USER” mode once the restoration is complete? What are the possible solutions to avoid this error?
When restore a database that already exists, the application automatically execute the following SQL command before restore:
ALTER DATABASE [db-name] SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
This ensures that all active sessions are terminated, allowing the restore process to proceed without conflicts.
However, if you are still encountering this error, we would need the Advanced Log to analyze the issue further. Could you please enable Advanced Log, reproduce the issue, and send us the logs? Here’s how you can do it: How to Send Logs to Developers