?
Solved

How to tell who is using a certain db ?

Posted on 2011-03-23
5
Medium Priority
?
248 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 8

Accepted Solution

by:
ragnarok89 earned 668 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 668 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 664 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

777 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