Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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?

share|improve this question
    
@SQLFox thanks. It just a load of SQL Management Studio instances. If I take it offline I can still restore OK yeah? –  rhughes Jul 17 '13 at 15:15
add comment

1 Answer

up vote 5 down vote accepted

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' 
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.