I'm creating the database backup, but I can not restore it. It shows the following error:
Thisismycodetoperformtherestoreofthebanktomyapplication.
try{var_with1=openFileDialog1;_with1.Filter=("DB Backup File|*.bak;");
_with1.FilterIndex = 4;
//Clear the file name
openFileDialog1.FileName = "";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
Cursor = Cursors.WaitCursor;
timer2.Enabled = true;
SqlConnection.ClearAllPools();
cg.con = new SqlConnection(cn.DBconn);
cg.con.Open();
string cb = "USE Master ALTER DATABASE [" + Application.StartupPath + "\SISTEMA_CCA.bak] SET Single_User WITH Rollback Immediate Restore database [" + Application.StartupPath + "\SISTEMA_CCA.bak] FROM disk='" + openFileDialog1.FileName + "' WITH REPLACE ALTER DATABASE [" + Application.StartupPath + "\SISTEMA_CCA.bak] SET Multi_User ";
cg.cmd = new SqlCommand(cb);
cg.cmd.Connection = cg.con;
cg.cmd.ExecuteReader();
cg.con.Close();
st1 = LB_Usuario.Text;
st2 = "Restauração realizada com sucesso";
cf.LogFunc(st1, System.DateTime.Now, st2);
MessageBox.Show("Operação concluída com sucesso", "Restuaração do banco de dados", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Thank you so much!