Solved

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

Posted on 2015-01-26
16
168 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 150 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
 
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 45

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 45

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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 45

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 45

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 45

Assisted Solution

by:Vitor Montalvão
Vitor Montalvão earned 350 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 45

Accepted Solution

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

Expert Comment

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

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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 Detach & Attach 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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 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