I am trying to run this SQL script on a SQL Server instance to restore a test database to a newer copy of the live database.
RESTORE FILELISTONLY
FROM disk = '\\staging_server\path\to\db_backup.bak'
-- Restore the files for
RESTORE DATABASE Test_DB
FROM disk = '\\staging_server\path\to\db_backup.bak'
WITH replace,
MOVE 'Test_DB' TO 'D:\R2_BIN\Test_DB.mdf',
MOVE 'Test_DB_log' TO 'D:\R2_BIN\Test_DB_log.ldf',
stats = 5
GO
However, on running the script I receive the following error.
Msg 3101, Level 16, State 1, Line 5
Exclusive access could not be obtained because the database is in use.
Msg 3013, Level 16, State 1, Line 5
RESTORE DATABASE is terminating abnormally.
Is there some way I can force this operation to go through, and kill any connections it needs to to get it done? I tried to close down any applications that may connections to the DB, but some of the connections I simply cannot identify. There are several from my username and yet I only have one instance of SQL Server Management Studio open.
Anyway, is there some way to kill all connections to a specific database? There are quite a few databases running on this instance, so I don't want to just shutdown and restart the instance all together if I can help it.