I have problems with this problem! My application is in Windows Forms. I need to back up the data through the application itself, but when I run to perform it it informs me of this error. https://i.stack.imgur.com/e5cq8.jpg ">
Note: My backup is on a non-local network server.
This is my code to back up.
try
{
Cursor = Cursors.WaitCursor;
timer2.Enabled = true;
if ((!System.IO.Directory.Exists(@"C:\DBBackup")))
{
System.IO.Directory.CreateDirectory(@"C:\DBBackup");
}
string destdir = "C:\DBBackup\SISTEMA_CCA " + DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss") + ".bak";
cg.con = new SqlConnection(cn.DBconn);
cg.con.Open();
string cb = "backup database SISTEMA_CCA to disk='" + destdir + "'with init,stats=10";
cg.cmd = new SqlCommand(cb);
cg.cmd.Connection = cg.con;
cg.cmd.ExecuteReader();
cg.con.Close();
st1 = LB_Usuario.Text;
st2 = "Backup realizado com sucesso";
cf.LogFunc(st1, System.DateTime.Now, st2);
MessageBox.Show("Operação concluída com sucesso", "Backup - Banco de dados", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Erro ao Fazer o Backup", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
Thank you in advance!