Solved

How to tell who is using a certain db ?

Posted on 2011-03-23
5
244 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
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.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

786 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