SQL Server error 3101: Exclusive access could not be obtained
RESTORE needs the database to itself, but other sessions are connected to it. Put it in single-user mode or close the connections first.
- Error number
3101- Severity
- 16
- Category
- Backup and restore
What it means
Restoring over a database replaces it completely, so nobody else may be using it. If any session is connected to the target database, including your own query window or Object Explorer, the restore fails with 3101 (followed by 3013).
Common causes
- Applications, jobs or other users connected to the database.
- Your own connection has the target database as its current database.
- Object Explorer or another tool browsing the database.
How to fix it
-
Switch your own session away from the database, then disconnect everyone else and restore.
USE master; ALTER DATABASE SalesDb SET SINGLE_USER WITH ROLLBACK IMMEDIATE; RESTORE DATABASE SalesDb FROM DISK = N'D:\Backup\SalesDb.bak' WITH REPLACE; ALTER DATABASE SalesDb SET MULTI_USER;
-
See who is connected.
SELECT session_id, login_name, host_name, program_name FROM sys.dm_exec_sessions WHERE database_id = DB_ID(N'SalesDb');
Related errors
3702Cannot drop database, currently in use5030Database couldn't be exclusively locked3013BACKUP or RESTORE ended abnormally
More backup and restore errors
3154Backup set is of a different database3201Cannot open backup device5120Unable to open the physical file
The code and message text are from the Microsoft Database Engine events and errors reference. Browse the full SQL Server error list or search every database error.
Work on SQL Server in SQLly
A native SQL client for macOS, Windows and Linux with schema-aware IntelliSense, guardrails for risky statements and clear error messages, for SQL Server and the other databases you use.