Example #1
0
        private void BackupButtonClick(object sender, RoutedEventArgs e)
        {
            string fileName = string.Format("SchoolBackup_{0}.bak", DateTime.Now.ToString("yyyy_MM_dd_h_mm_tt"));

            makeVisible();
            progressBarr.Value = 0;
            try
            {
                Server dbServer = new Server(new ServerConnection(System.Environment.MachineName));
                Microsoft.SqlServer.Management.Smo.Backup dbBackup = new Microsoft.SqlServer.Management.Smo.Backup()
                {
                    Action = BackupActionType.Database, Database = "School"
                };
                dbBackup.Devices.AddDevice(@backupDirectory() + "\\" + fileName, DeviceType.File);
                dbBackup.Initialize = true;
                dbBackup.SqlBackupAsync(dbServer);

                progressBarr.Value = 100;
                this.ShowMessageAsync("Backup", "Backup Completed!");
                lastBackup.Content = DateTime.Now.ToString("yyyy-MM-dd h:mm tt");
            }
            catch (Exception err)
            {
                System.Windows.MessageBox.Show(err.ToString());
            }
        }
Example #2
0
 private void btnBackUp_Click(object sender, EventArgs e)
 {
     progressBar.Value = 0;
     try
     {
         Server DbServer = new Server(new ServerConnection(txtServer.Text));
         Microsoft.SqlServer.Management.Smo.Backup dbBackup = new Microsoft.SqlServer.Management.Smo.Backup()
         {
             Action = BackupActionType.Database, Database = txtDatabase.Text
         };
         dbBackup.Devices.AddDevice(@txtPath.Text + "RoshanTraders" + DateTime.Now.ToShortDateString() + ".bak", DeviceType.File);
         dbBackup.Initialize = true; dbBackup.PercentComplete += DbBackup_PercentComplete;
         dbBackup.Complete  += DbBackup_Complete;
         dbBackup.SqlBackupAsync(DbServer);
         MessageBox.Show("Backup Completed");
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }