Solved

How to tell who is using a certain db ?

Posted on 2011-03-23
5
242 Views
Last Modified: 2012-05-11
Hi Experts,

I need to restore a Sandbox db. But during restoring I got an error saying the db is in use by others and can not go any further. The problem is, how to tell who is using a certain db??
Thanks.
0
Comment
Question by:Castlewood
5 Comments
 
LVL 8

Accepted Solution

by:
ragnarok89 earned 167 total points
ID: 35200944
run the query

sp_who
0
 

Author Comment

by:Castlewood
ID: 35201346
Ok, I got the username who uses this db. The status shows 'sleeping'. So is there anyway to cut off the connection?
0
 
LVL 14

Assisted Solution

by:Daniel_PL
Daniel_PL earned 167 total points
ID: 35201565
Note session spid number (e.g. from sp_who2) and use:
kill <spid number>
0
 
LVL 5

Assisted Solution

by:bitref
bitref earned 166 total points
ID: 35203172
You can monitor the processes using the database and kill them using the Activity Monitor. You can find its icon in the Standard Toolbar of SQL Server Management Studio.
0
 
LVL 14

Expert Comment

by:Daniel_PL
ID: 35213012
When you are restoring database you can automatically remove activity from your database by altering database state to single user:
USE MASTER
GO
ALTER DATABASE <database name>
SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
RESTORE DATABASE <database name>
FROM DISK =N'<path to backup file>'
GO

Open in new window

0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now