0
I am creating the database backup but cannot restore. It shows the following error:
this is my code to perform bank restore to my application.
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);
}
from now on thank you guys!
I went through something similar a while ago and if I’m not mistaken it was because of the " " and it was for SISTEMA_CCA.Bak in all arguments? just like . Startuppath? The application is on the same machine as the database?
– Leandro Angelo
Yes application is on the same machine as the database, until I finish the system, when I finish the system the database will be on the database server and the system on another server.
– Lucas_Silva
@Leandroangelo you could explain to me how you solved your problem. As you said you went through almost the same situation hugs!
– Lucas_Silva