Sql-server – Restore SQL Server 2000 Database in use

backuprestoresql-server-2000

I need to restore a SQL Server 2000 database to a backup of about 2 days ago. I have just backed it up and have tried to restore it, but it says it is in use.

What is the best way to find out who is still using it and then how to disconnect them?

I imagine taking the DB offline is a simple way of doing it, but probably not the safest?

Best Answer

Running sp_who2 will show you who is connected to the database.

The safest way to disconnect users is to ask them to disconnect themselves. If that is not practical, you can take the database offline or set it to SINGLE_USER mode to force the other connections out before performing your restore.

See this for more information and examples:

ALTER DATABASE [Test4] SET SINGLE_USER WITH ROLLBACK IMMEDIATE  

RESTORE DATABASE [Test4] 
FROM DISK = 'c:\test4.BAK' 
WITH MOVE 'Test4_Data' TO 'c:\data\Test4.mdf', 
MOVE 'Test4_Log' TO 'c:\data\Test4_log.ldf'