Can't restore sql database, show user in use

litmic
litmic used Ask the Experts™
on
What's the function of ms sql database take offline? How to disconnect the database users connections?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
sp_who2 shows all connections. If you see somebody connected just KILL the process. Then you may switch the database to single user mode which avoids other users connections:

USE master;
GO
ALTER DATABASE YourDatabaseName
SET SINGLE_USER
WITH ROLLBACK IMMEDIATE;
GO

And now you may restore the backup.

How to take the database offline is described e.g. here: https://blog.sqlauthority.com/2010/04/24/sql-server-t-sql-script-to-take-database-offline-take-database-online/

Author

Commented:
Thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial