Solved

How to tell who is using a certain db ?

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
sql query 8 51
Challenging SQL Update 5 49
SQL Insert parts by customer 12 42
SSRS: Why is Visual Studio stripping these properties? 2 23
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

829 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