private void btnSauvegarde_Click(object sender, EventArgs e) { try { ap.connect(); con = new SqlConnection(ap.chemin); string database = con.Database.ToString(); if (bd.getBackupPath(radioButton3, personalizePath) == string.Empty) { MessageBox.Show("Veuillez selectionner d'abord un emplacement s.v.p.!"); } else { string cmd = "BACKUP DATABASE [" + database + "] TO DISK='" + bd.getBackupPath(radioButton3, personalizePath) + "\\" + database + "-" + DateTime.Now.ToString("yyyy-MM-dd--HH-mm-ss") + ".bak'"; using (SqlCommand command = new SqlCommand(cmd, con)) { if (con.State != ConnectionState.Open) { con.Open(); } command.ExecuteNonQuery(); con.Close(); MessageBox.Show("Sauvegarde effectué avec succés", "Confirmation Sauvegarde"); } } } catch (Exception exc) { MessageBox.Show(exc.Message); } }
private void userBuckup_Load(object sender, EventArgs e) { try { defaultPath.Text = bd.getBackupPath(radioButton3, personalizePath); } catch (Exception) { } }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { try { ap.connect(); myconn = new SqlConnection(ap.chemin); string database = myconn.Database.ToString(); string cmd = "BACKUP DATABASE [" + database + "] TO DISK='" + bc.getBackupPath() + "\\" + database + "-" + DateTime.Now.ToString("yyyy-MM-dd--HH-mm-ss") + ".bak'"; using (SqlCommand command = new SqlCommand(cmd, myconn)) { if (myconn.State != ConnectionState.Open) { myconn.Open(); } command.ExecuteNonQuery(); myconn.Close(); //XtraMessageBox.Show("Sauvegarde effectué avec succés", "Confirmation Sauvegarde"); } } catch (Exception exc) { MessageBox.Show(exc.Message); } }