RESTORE cannot process database because it is in use by this session

2821
Views
1
Answers

I am trying to restore my database with REPLACE function as suggested.Here is the SQL Script

RESTORE DATABASE MYDATABASE
FROM DISK
= 'C:\DBBackup.bak'
WITH REPLACE

Now it throws another error saying

  Msg 3102, Level 16, State 1, Line 1 
  RESTORE cannot process database
'MYDATABASE' because it is in use by this session.
 
It is recommended that the master database be used when performing this operation.

Any Suggestions!!??

edit | flag
Mike Carpenter
Asked on: Feb 04, 2012 at 6:39AM

1 Answers

122
1
122

This is because the user database has an active connection with your current session. Try changing database connection to a different database by using USE DATABASE. Like...

USE master 
RESTORE DATABASE MYDATABASE
FROM DISK
= 'C:\DBBackup.bak'
WITH REPLACE
edit | flag
Gokul A
Answered on: Feb 04, 2012 at 6:43AM

Post your Answer

Search

Welcome to Ask Amoeba!
This is 100% free and interactive site for sharing professional Questions and Answers, Opensource projects, Interview questions.
Learners, beginners, Experts stop and share your knowledge and ideas!

Browse Categories

Browse Tags