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
SSC-Forever
SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)SSC-Forever (46K reputation)

Group: General Forum Members
Points: 46585 Visits: 10150
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
SSC Rookie
SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)SSC Rookie (37 reputation)

Group: General Forum Members
Points: 37 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
SSCoach
SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)SSCoach (19K reputation)

Group: General Forum Members
Points: 19247 Visits: 3813
Good.

Thanks.
Dennis Post
Dennis Post
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2489 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
SSCertifiable
SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)

Group: General Forum Members
Points: 5572 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.
Raghavendra Mudugal
Raghavendra Mudugal
SSCertifiable
SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)SSCertifiable (5.6K reputation)

Group: General Forum Members
Points: 5572 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.
Lincoln Burrows
Lincoln Burrows
SSChampion
SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)SSChampion (10K reputation)

Group: General Forum Members
Points: 10789 Visits: 1234
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 Guru
SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)

Group: General Forum Members
Points: 224257 Visits: 33576
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
usriramachandra
usriramachandra
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 3
similar issue faced by me, i stopped and restarted the mssql server and agent in services.msc and then restored it worked
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