﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Administering / SQL Server 2005  / Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.' / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 25 May 2013 20:36:14 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.'</title><link>http://www.sqlservercentral.com/Forums/Topic1087930-146-1.aspx</link><description>Make sure no other instances of SSMS are open.If you have multiple tabs open, make sure they are [u]not[/u] 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?</description><pubDate>Thu, 27 Sep 2012 04:48:03 GMT</pubDate><dc:creator>Dennis Post</dc:creator></item><item><title>RE: Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.'</title><link>http://www.sqlservercentral.com/Forums/Topic1087930-146-1.aspx</link><description>Good.</description><pubDate>Thu, 27 Sep 2012 00:30:52 GMT</pubDate><dc:creator>SQL-DBA-01</dc:creator></item><item><title>RE: Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.'</title><link>http://www.sqlservercentral.com/Forums/Topic1087930-146-1.aspx</link><description>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.</description><pubDate>Thu, 27 Sep 2012 00:28:13 GMT</pubDate><dc:creator>lembit.kristian</dc:creator></item><item><title>RE: Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.'</title><link>http://www.sqlservercentral.com/Forums/Topic1087930-146-1.aspx</link><description>[quote][b]Grant Fritchey (4/5/2011)[/b][hr]True, but I prefer to not let anyone have privileged access to the server except other DBAs.[/quote]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.</description><pubDate>Tue, 05 Apr 2011 19:35:04 GMT</pubDate><dc:creator>Jeffrey Williams 3188</dc:creator></item><item><title>RE: Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.'</title><link>http://www.sqlservercentral.com/Forums/Topic1087930-146-1.aspx</link><description>Hi Sourav Mukherjee,       You can use the below command.ALTER DATABASE [mydb] SET SINGLE_USER WITH ROLLBACK IMMEDIATEGORESTORE DATABASE [mydb] FROM DISK='f:\backup\mydb.bak'GO</description><pubDate>Tue, 05 Apr 2011 15:08:17 GMT</pubDate><dc:creator>phaniverma.dba</dc:creator></item><item><title>RE: Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.'</title><link>http://www.sqlservercentral.com/Forums/Topic1087930-146-1.aspx</link><description>[quote][b]Jeffrey Williams-493691 (4/5/2011)[/b][hr][quote][b]Grant Fritchey (4/5/2011)[/b][hr]Can you try using restricted user instead of single user? I've seen applications that constantly refresh their connection so they can squeek in before you start the restore.[/quote]If this doesn't work, then you have some process refreshing its connection and is using a privileged account.I prefer taking the database offline myself - this insures that nobody can access that database and allows the restore to proceed with no problems.[/quote]True, but I prefer to not let anyone have privileged access to the server except other DBAs.</description><pubDate>Tue, 05 Apr 2011 14:53:18 GMT</pubDate><dc:creator>Grant Fritchey</dc:creator></item><item><title>RE: Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.'</title><link>http://www.sqlservercentral.com/Forums/Topic1087930-146-1.aspx</link><description>[quote][b]Grant Fritchey (4/5/2011)[/b][hr]Can you try using restricted user instead of single user? I've seen applications that constantly refresh their connection so they can squeek in before you start the restore.[/quote]If this doesn't work, then you have some process refreshing its connection and is using a privileged account.I prefer taking the database offline myself - this insures that nobody can access that database and allows the restore to proceed with no problems.</description><pubDate>Tue, 05 Apr 2011 14:17:44 GMT</pubDate><dc:creator>Jeffrey Williams 3188</dc:creator></item><item><title>RE: Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.'</title><link>http://www.sqlservercentral.com/Forums/Topic1087930-146-1.aspx</link><description>Can you try using restricted user instead of single user? I've seen applications that constantly refresh their connection so they can squeek in before you start the restore.</description><pubDate>Tue, 05 Apr 2011 05:17:54 GMT</pubDate><dc:creator>Grant Fritchey</dc:creator></item><item><title>RE: Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.'</title><link>http://www.sqlservercentral.com/Forums/Topic1087930-146-1.aspx</link><description>master</description><pubDate>Tue, 05 Apr 2011 03:16:18 GMT</pubDate><dc:creator>SQL-DBA-01</dc:creator></item><item><title>RE: Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.'</title><link>http://www.sqlservercentral.com/Forums/Topic1087930-146-1.aspx</link><description>What is the default database for the job step running the restore?</description><pubDate>Tue, 05 Apr 2011 03:12:56 GMT</pubDate><dc:creator>Ian Scarlett</dc:creator></item><item><title>RE: Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.'</title><link>http://www.sqlservercentral.com/Forums/Topic1087930-146-1.aspx</link><description>no, refresh of the database is being performed using a SQL JOB. I dont use the SSMS generally for this kind of tasks, it is prone to hang for large size bkps.</description><pubDate>Tue, 05 Apr 2011 03:05:40 GMT</pubDate><dc:creator>SQL-DBA-01</dc:creator></item><item><title>RE: Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.'</title><link>http://www.sqlservercentral.com/Forums/Topic1087930-146-1.aspx</link><description>Are you doing the restore from SSMS rather than a query?  When SSMS opens its restore window, it starts a session using your default database.  If this is the database you're trying to restore, you get the error described.  (This has always annoyed me).</description><pubDate>Tue, 05 Apr 2011 02:16:07 GMT</pubDate><dc:creator>Andrew Watson-478275</dc:creator></item><item><title>RE: Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.'</title><link>http://www.sqlservercentral.com/Forums/Topic1087930-146-1.aspx</link><description>Even if you place it in single user mode, if you're connected to that database or another connection is there, it might still be active when you try to run the backup. Generally I don't use single user mode, I use restricted user, but that assumes that most of our logins are not 'sa' and the ones that are I can kill or identify and alert individually.</description><pubDate>Mon, 04 Apr 2011 06:33:06 GMT</pubDate><dc:creator>Grant Fritchey</dc:creator></item><item><title>Restore Database Failed: 'Exclusive access could not be obtained because the database is in use.'</title><link>http://www.sqlservercentral.com/Forums/Topic1087930-146-1.aspx</link><description>Hi,While trying to restore a database (with replace option), I am getting the below error -Exclusive access could not be obtained because the database is in use. [SQLSTATE 42000] (Error 3101)  RESTORE DATABASE is terminating abnormally. [SQLSTATE 42000] (Error 3013).  The step failed.Though, before kicking off the refresh, I took the database in 'single user' mode and also used the below script to KILL all the connected sessions.DECLARE @SPIDSTR varchar(8000)DECLARE @ConnKilled smallintDECLARE @DBName varchar(100)SET @SPIDSTR = ''SET @ConnKilled = 0;SET @DBName = '&amp;lt;database&amp;gt;'SELECT @SPIDSTR=coalesce(@spidstr,',' )+'KILL '+convert(varchar, spid)+ '; 'FROM MASTER..SYSPROCESSES WHERE dbid=db_id(@DBName);Print @SPIDSTR;IF LEN(@spidstr) &amp;gt; 0 BEGINEXEC(@spidstr);Print @SPIDSTR;	SELECT @ConnKilled = COUNT(1)	FROM master..sysprocesses WHERE dbid=db_id(@DBName) ENDCan you please suggest, what went wrong, in my adhered process?Atlast, I had to drop the database and now when I am trying to restore, it is working fine.Kindly suggest with your opinion.</description><pubDate>Mon, 04 Apr 2011 02:02:16 GMT</pubDate><dc:creator>SQL-DBA-01</dc:creator></item></channel></rss>