Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Cannot drop database "MYDB" because it is currently in use.

Posted on 2015-01-26
16
Medium Priority
?
371 Views
Last Modified: 2015-01-30
Hi..
trying to drop a DB... can't take it offline.. just runs and runs...

lock could not be placed... don't see processes..

any ideas

Cannot drop database "MYDB" because it is currently in use.
0
Comment
Question by:JElster
  • 7
  • 7
  • 2
16 Comments
 
LVL 52

Assisted Solution

by:Carl Tawn
Carl Tawn earned 600 total points
ID: 40570462
Are you trying to drop it from the GUI or from a DDL statement? Odds are you have a connection open to it, so you will need to close that first - or kill it.

You can run the following query to see who or what is connected to it:
select original_login_name, db_name(database_id) from sys.dm_exec_sessions
where db_name(database_id) = 'MyDB'

Open in new window

0
 
LVL 1

Author Comment

by:JElster
ID: 40570475
nobody else is in
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 40570494
nobody else except you, or nobody at all?
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 1

Author Comment

by:JElster
ID: 40570500
In this particular DB

ALTER DATABASE failed because a lock could not be placed on database ''. Try again later.
0
 
LVL 52

Expert Comment

by:Vitor Montalvão
ID: 40570502
You need to close all existing connections. There's a checkbox that by default is unchecked so you need to check it before delete the database.

Capture.PNG
0
 
LVL 1

Author Comment

by:JElster
ID: 40570522
Get database in use...... ???????????????????  even when selecting close existing connections
0
 
LVL 52

Expert Comment

by:Vitor Montalvão
ID: 40570540
Ok. I also prefer to do it by script that by GUI :)

In SSMS open a new query a run the following script:
USE [master]
GO
ALTER DATABASE MYDB SET  SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
DROP DATABASE MYDB
GO

Open in new window

0
 
LVL 1

Author Comment

by:JElster
ID: 40570554
Msg 5061, Level 16, State 1, Line 1
ALTER DATABASE failed because a lock could not be placed on database 'ONBOARD'. Try again later.
Msg 5069, Level 16, State 1, Line 1
ALTER DATABASE statement failed.
Msg 3702, Level 16, State 4, Line 1
Cannot drop database "ONBOARD" because it is currently in use.
0
 
LVL 52

Expert Comment

by:Vitor Montalvão
ID: 40570560
What do you have running on that database?
0
 
LVL 1

Author Comment

by:JElster
ID: 40570573
The server has other DB's... nothing is running or accessing this particular DB
????????
0
 
LVL 52

Expert Comment

by:Vitor Montalvão
ID: 40570583
Can you check by running sp_who2?
0
 
LVL 1

Author Comment

by:JElster
ID: 40570597
nobody is in this db
0
 
LVL 52

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 1400 total points
ID: 40570700
Ok, then the question that I should made at the first time:
- What happened for you want to drop the database?

Also, can you post here the result from the following query?
select
    l.resource_type,
    l.request_mode,
    l.request_status,
    l.request_session_id,
    r.command,
    r.status,
    r.blocking_session_id,
    r.wait_type,
    r.wait_time,
    r.wait_resource,
    request_sql_text = st.text,
    s.program_name,
    most_recent_sql_text = stc.text
from sys.dm_tran_locks l
left join sys.dm_exec_requests r
on l.request_session_id = r.session_id
left join sys.dm_exec_sessions s
on l.request_session_id = s.session_id
left join sys.dm_exec_connections c
on s.session_id = c.session_id
outer apply sys.dm_exec_sql_text(r.sql_handle) st
outer apply sys.dm_exec_sql_text(c.most_recent_sql_handle) stc
where l.resource_database_id = db_id('ONBOARD')
order by request_session_id

Open in new window

0
 
LVL 1

Author Comment

by:JElster
ID: 40570723
DATABASE      S      GRANT      137      KILLED/ROLLBACK      suspended      0      LOGBUFFER      327845604            NULL      Microsoft SQL Server Management Studio - Query
DATABASE      S      GRANT      164      NULL      NULL      NULL      NULL      NULL      NULL      NULL      Microsoft SQL Server Management Studio - Query
0
 
LVL 52

Accepted Solution

by:
Vitor Montalvão earned 1400 total points
ID: 40570738
So, you already have a ROLLBACK running. You can't do nothing but wait for the rollback finish.
0
 
LVL 52

Expert Comment

by:Vitor Montalvão
ID: 40579231
How long the rollback took?
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

In this article I will describe the Backup & Restore 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.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Integration Management Part 2
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

916 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