i am using the following code snippet to backup/restore database
Backup works fine but when i try to restore i get this error
“RESTORE cannot process database ‘LIC’ 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.”
If strAction = Action.BackUp Then
strQuery = "BACKUP DATABASE LIC to disk='C:\Backup\ICLS.bak'"
Else
strQuery = "RESTORE DATABASE LIC FROM disk='C:\Backup\ICLS.bak'"
End If
Dim cmd As SqlCommand
cmd = New SqlCommand(strQuery, con)
cmd.ExecuteNonQuery()
MsgBox("Restore Done")
Like the message says, you are connected to the database you’re trying to restore. Change your connection string to use the Master database and then restore.