Error while backing up in wpf c #

0

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);
        }
    }
    
asked by anonymous 19.02.2018 / 20:04

1 answer

0

I was able to solve my problem. I was providing a parameter in place of the database.

The backup command has this form

backup database database_name to DISK = backup path + file_name backback with [options]

Then correct this line for this

string cb="backup database SISTEMA_CCA to disk = '" + destdir + "' with init, stats = 10";

Problem solved!

    
20.02.2018 / 19:49