I'm having trouble backing up my system.
I'm using WPF with SQLSERVER 2008 , in this system I need to back up the data on the local machine of the client, so to create the directory of the backup on Disk C:\
.
But he is returning this error, I have been researching on the subject he says it is permission, but I already gave permission in both the sqlserver and in the folder inside the IOS / p>
follows the image of the error and my code.
privatevoidbackupSistemaToolStripMenuItem_Click(objectsender,EventArgse){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 [" + Application.StartupPath + "\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, 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, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}