Click here to Skip to main content
15,899,124 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
try
{
  gn.open();
  string str;
                
  str = @"RESTORE DATABASE bw FROM DISK = 'C:\SQLBackup\bw.bak'";
  SqlCommand cmd = new SqlCommand(str, gn.cn());
  cmd.ExecuteNonQuery();
}

i tried above coding to restore database using windows application ., i am getting error like.,
SQL
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
Posted
Updated 6-Sep-12 20:33pm
v2

1 solution

Hi Umapathi,
Alternate solution for this is create another database and connect on that database and then execute your script.
for ex. If You are going to restore database TempDb than create anothere database TempDB_Conn and when you want to restore db that time connect TempDB_Conn.

May be this help you....
 
Share this answer
 
Comments
Umapathi K 7-Sep-12 2:39am    
i have created another database called 'bww' as you said. error showing like this

the backup set holds a backup of a database other than the
existing 'bww' database
restore database is terminating abnormally

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900