Quantcast
Channel: Couldn't restore database and couldn't change Single user mode to Multi user mode - Database Administrators Stack Exchange
Viewing all articles
Browse latest Browse all 2

Couldn't restore database and couldn't change Single user mode to Multi user mode

$
0
0

I am unable to restore a database.

The database is stuck in single user mode. I cannot change to multi-user mode.

I was restoring the SQL Server database from Prod to Dev as I have done many times without issue.

I run the following scripts:

--1use mastergoALTER DATABASE [Acct] SET SINGLE_USER WITH ROLLBACK IMMEDIATEGo

The database changed to single user mode.

--2RESTORE DATABASE [Acct] FROM  DISK = N'D:\Restore_Backup\Restore_05042015\ProdAcct.bak'WITH  FILE = 1,  MOVE N'ProdAcct' TO N'D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Acct.mdf',  MOVE N'ProdAcct_log' TO N'D:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\Acct_log.ldf',   NOUNLOAD,  REPLACE,  STATS = 10GOError: Msg 3101, Level 16, State 1, Line 1Exclusive access could not be obtained because the database is in use.Msg 3013, Level 16, State 1, Line 1RESTORE DATABASE is terminating abnormally.--3 I run the following script to see the connection select d.name, d.dbid, spid, login_time, nt_domain, nt_username, loginame  from sysprocesses p inner join sysdatabases d on p.dbid = d.dbid where d.name = 'Acct'go--4 kill the connectionKill 85Kill 51--5exec sp_dboption 'Acct', 'single user', 'FALSE'go

and I've tried:

ALTER DATABASE [Acct] SET MULTI_USERGo

Both commands fail.

--6select d.name, d.dbid, spid, login_time, nt_domain, nt_username, loginame  from sysprocesses p inner join sysdatabases d on p.dbid = d.dbid where d.name = 'Acct'go--7 connection 51 was  accessingkill 51

But I wasn't able to kill it.

At this point I had to call the application owners and asked them to stop the applications they were running. After they stopped their app, I was able to restore the database.

Question:

  1. What kind of mistake did I make to run into this kind of problem?
  2. Is there a way I am able to restore without asking people to stop their application whenever I want to refresh the Dev database?

Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images