SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.'


Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.'

Author
Message
Jeffrey Williams 3188
Jeffrey Williams 3188
SSCertifiable
SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)SSCertifiable (7.7K reputation)

Group: General Forum Members
Points: 7739 Visits: 9971
Grant Fritchey (4/5/2011)
True, but I prefer to not let anyone have privileged access to the server except other DBAs.


Of course, I would prefer that also - but I have various systems where the vendors have setup their applications to use privileged accounts. I don't have a choice...unfortunately.

Jeffrey Williams
Problems are opportunities brilliantly disguised as insurmountable obstacles.

How to post questions to get better answers faster
Managing Transaction Logs

lembit.kristian
lembit.kristian
Forum Newbie
Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)Forum Newbie (3 reputation)

Group: General Forum Members
Points: 3 Visits: 12
In my case: I was logged in to SSMS as 'user_x'. Default database for 'user_x' was 'Test_DB'.
I got same errormessage when I tried to restore in this session 'Test_DB'.

When I logged out as 'user_x' and logged in SSMS as another user (that did not have default database 'Test_DB'), restore was successful.
SQL-DBA-01
SQL-DBA-01
Hall of Fame
Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)Hall of Fame (3.7K reputation)

Group: General Forum Members
Points: 3679 Visits: 3293
Good.

Thanks.
Dennis Post
Dennis Post
Old Hand
Old Hand (391 reputation)Old Hand (391 reputation)Old Hand (391 reputation)Old Hand (391 reputation)Old Hand (391 reputation)Old Hand (391 reputation)Old Hand (391 reputation)Old Hand (391 reputation)

Group: General Forum Members
Points: 391 Visits: 547
Make sure no other instances of SSMS are open.
If you have multiple tabs open, make sure they are not pointing to the DB in question.

You could also try restarting the service.

Any replication going on? Or any other jobs or triggers pointing to your troublesome DB?



For better, quicker answers on T-SQL questions, read Jeff Moden's suggestions.

"Million-to-one chances crop up nine times out of ten." ― Terry Pratchett, Mort
Raghavendra Mudugal
Raghavendra Mudugal
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2096 Visits: 2958
Dennis Post (9/27/2012)
...
If you have multiple tabs open, make sure they are not pointing to the DB in question...


This helped and fixed the problem, thank you

(Using... MSSQL 2012 DEV EDT)

Msg 3101, Level 16, State 1, Line 2
Exclusive access could not be obtained because the database is in use.
Msg 3013, Level 16, State 1, Line 2
RESTORE DATABASE is terminating abnormally.



(after logs growth due to uncommitted transaction and also data was being inserted at the same time.. the log is in a huge size and adding additional log then backup-ing the log and restoring the database full backup and restoring the recent log..... all things came to normal)

ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
samanta0rodriges
samanta0rodriges
Forum Newbie
Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)Forum Newbie (7 reputation)

Group: General Forum Members
Points: 7 Visits: 6
What is the default database for the job step running the restore?

daily deals, online shopping sites, hot deals, best deals
Raghavendra Mudugal
Raghavendra Mudugal
SSCrazy
SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)SSCrazy (2.1K reputation)

Group: General Forum Members
Points: 2096 Visits: 2958
samanta0rodriges (7/30/2014)

What is the default database for the job step running the restore?


basically and mainly, the usage of the default DB points to "MASTER", as I did the same to.

Are you also facing the same problem?

(if no then great, if yes... then post any errors appeared and steps here so we can also learn from that, thank you)

ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
JasonClark
JasonClark
SSCommitted
SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)SSCommitted (1.6K reputation)

Group: General Forum Members
Points: 1642 Visits: 1027
you must set the database to single user mode before attempting to restore see here: http://www.sqlserverlogexplorer.com/exclusive-access-not-obtained-database-use/
Grant Fritchey
Grant Fritchey
SSC-Forever
SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)SSC-Forever (40K reputation)

Group: General Forum Members
Points: 40086 Visits: 32653
jacksonandrew321 (4/4/2016)
you must set the database to single user mode before attempting to restore see here: http://www.sqlserverlogexplorer.com/exclusive-access-not-obtained-database-use/


This is a two year old thread.

You don't have to set the database to single user in order to restore a database. You do have to have exclusive access to the database you're restoring. One way of doing that can be to set the database to single user, although, if another connection is already there, that can cause problems. I generally go for restricted user, but, in this case, the third party apps all need privileged access, so that won't work either. Best approach here is likely just to kill every connection first.

----------------------------------------------------
The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood...
Theodore Roosevelt

The Scary DBA
Author of: SQL Server Query Performance Tuning and SQL Server Execution Plans
Product Evangelist for Red Gate Software
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search