debugsqlMinor
Error in restore database
Viewed 0 times
databaseerrorrestore
Problem
I use this query in SQL Server 2008 R2 to restore
The following error is displayed:
Msg 3102, Level 16, State 1, Line 1
RESTORE cannot process database 'DB1' because it is in use by this session. It is recommended that the master database be used when performing this operation.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
DB1 database:RESTORE DATABASE [DB1]
FROM DISK = N'D:\new.bak'
WITH RESTRICTED_USER, FILE = 1, NOUNLOAD, REPLACE, STATS = 10;The following error is displayed:
Msg 3102, Level 16, State 1, Line 1
RESTORE cannot process database 'DB1' because it is in use by this session. It is recommended that the master database be used when performing this operation.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
Solution
The message seems pretty clear: you cannot be using the
So in SQL Server Management Studio, first close all windows that are open and using that database! Then run this:
DB1 database when trying to restore it - instead, use the master database!So in SQL Server Management Studio, first close all windows that are open and using that database! Then run this:
USE master
GO
RESTORE DATABASE [DB1]
FROM DISK = N'D:\new.bak'
WITH RESTRICTED_USER, FILE = 1, NOUNLOAD, REPLACE, STATS = 10;Code Snippets
USE master
GO
RESTORE DATABASE [DB1]
FROM DISK = N'D:\new.bak'
WITH RESTRICTED_USER, FILE = 1, NOUNLOAD, REPLACE, STATS = 10;Context
StackExchange Database Administrators Q#30865, answer score: 9
Revisions (0)
No revisions yet.