Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL-server-2005
restore cannot process database 'bw' because it is in use
by this session. It is recommended that the master database
be used when performing this operation.
restore database is terminating abnormally
 

Note: Here 'bw' is my DB name.,
Posted 9-Sep-12 20:00pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try to run your restore operation in master database. It looks like you have selected the "BW" database while running the restore operation.
 
The below command will select the master database and then you can execute the restore database command.
USE Master
  Permalink  
v2
Comments
Prasad_Kulkarni at 10-Sep-12 2:20am
   
5'ed, :D
__TR__ at 10-Sep-12 2:27am
   
Thanks :)
Umapathi K at 10-Sep-12 2:28am
   
str = "USE MASTER RESTORE DATABASE bw FROM DISK = 'c:\\SQLBackup\\bw.bak' WITH MOVE 'bw' TO 'c:\\SQLBackup\\bw.mdf' , MOVE 'bw_Log' TO 'C:\\SQLBackup\\bw.ldf', REPLACE ";
 
i used above codig but its not restoring
__TR__ at 10-Sep-12 2:52am
   
Are you executing your SQL statements in a query window?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Try prefixing your restore with:
USE MASTER
GO
<your restore statements>
At present, I suspect that you are opening a new query window on the DB you want to restore which will put an implicit
USE BW
GO
in front of the query.
If the DB is in use, it cannot be restored to.
  Permalink  
Comments
Umapathi K at 10-Sep-12 2:09am
   
str = "USE MASTER RESTORE DATABASE bw FROM DISK = 'c:\\SQLBackup\\bw.bak' WITH MOVE 'bw' TO 'c:\\SQLBackup\\bw.mdf' , MOVE 'bw_Log' TO 'C:\\SQLBackup\\bw.ldf', REPLACE ";
 
i used above coding but not restoring
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Try SMO way of doing this:
SQL Server 2008 - Backup and Restore Databases using SMO[^]
 
More detailed examples:
http://www.mssqltips.com/sqlservertip/1849/backup-and-restore-sql-server-databases-programmatically-with-smo/[^]
 
Note:*****Yes! you have dependancy on MS SQL Server(definitely) if you choose to do this way.
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 375
1 Sergey Alexandrovich Kryukov 170
2 CHill60 160
3 RyanDev 135
4 Richard MacCutchan 115


Advertise | Privacy | Mobile
Web01 | 2.8.140709.1 | Last Updated 10 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid