Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Register Now and get your question answered!
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Data Corruption Issues
 How can I recover SQL database from stuck mode?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

52 Posts

Posted - 08/04/2014 :  07:06:06  Show Profile  Reply with Quote
Hello. Actually I was clearing tables by using query in SQL database. A query that normally takes 2 minutes took the better part of 3 hours...and it wasn’t even close to being complete. Therefore, i killed SQL in task manager because I felt like I had no other choice.

Upon logging back in, the database has been (in Recovery). According to various post i read online, simply detaching it and reattaching it should work fine however, when i try to run queries to detach it i get the following error.
Alter database failed because a lock couldn’t be obtained for database <selcon>
I also read that this was due to a connection not being terminated but everything i tried gives that same lock error. I made sure i was in master, i reset the pc, un-plug network table, tried the commands in the GUI. Nothing's letting me detach said database or remove it from In recovery.
Any help would be appreciated. Thank you

Almighty SQL Goddess

38200 Posts

Posted - 08/04/2014 :  12:23:41  Show Profile  Visit tkizer's Homepage  Reply with Quote
You need to stop doing all of those steps and let the database recover. You canceled a large transaction, and it needs to rollback. You can check the Error Log for its progress as SQL will report the percentage of the 3 phases.

I don't understand the posts saying to detach/attach. That doesn't make sense.

Tara Kizer
SQL Server MVP since 2007
Go to Top of Page

Starting Member

1 Posts

Posted - 08/05/2014 :  04:31:59  Show Profile  Reply with Quote
If you notice in MS SQL Management Studio that a database is stuck in restoring mode, open a new query by clicking on the 'new query' button and enter the following command:


Click on 'Execute'. When you refresh MS SQL Management Studio, the database will be in a normal operational state.
Go to Top of Page

Yak Posting Veteran

52 Posts

Posted - 09/04/2014 :  06:29:14  Show Profile  Reply with Quote
Thanks Camero for your help.
Go to Top of Page

Flowing Fount of Yak Knowledge

United Kingdom
2179 Posts

Posted - 09/05/2014 :  01:49:45  Show Profile  Visit jackv's Homepage  Reply with Quote
Normally , you'd kill the transaction as opposed to closing down SQL Server - to monitor transaction rollback - utilise this query -

Jack Vamvas
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.07 seconds. Powered By: Snitz Forums 2000