0
I am having trouble performing backup on my system.
I’m using WPF with SQLSERVER 2008, on that system I need to backup the data on the client’s local machine, then I’m creating the backup directory on Disk C:\\
.
However he is returning me this error, I’ve been researching on the subject says it is permission, but I’ve given both permission in sqlserver and in the folder IOS.
follows the error image and my code.
private void backupSistemaToolStripMenuItem_Click(object sender, EventArgs e)
{
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);
}
}
This is because file creation is delegated to the database, regardless of where the executable is. That is, SQL Server will try to save the backup in this folder on the database server.
– Jéf Bueno
Good morning Erlon. Dear you could help me solve this problem
– Lucas_Silva