Backup:
private void Button1_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("backup database emp to disk ='C:\\emp.bak'", con);
con.Open();
cmd.ExecuteNonQuery();
// ExecutenonQuery();
con.Close();
}
But when I restore:
private void Button2_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("restore database emp from disk ='C:\\emp.bak'", con);
con.Open();
cmd.ExecuteNonQuery();
// ExecutenonQuery();
con.Close();
}
I get the error:
RESTORE cannot process database 'emp' 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.
Anyone can help me please