internal void TakeBackUp() { //if(MessageConfirmation.MessageShowYesNo("Do you want to take back up?")) // if (MessageBox.Show("Do you want to take back up?", "A2zSchool", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) if (MessageBox.Show("Do you want to take back up?", "Bank", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (sqlcon.State == ConnectionState.Closed) { sqlcon.Open(); } string DBName = sqlcon.Database; ; string[] arr = DBName.Split('\\'); DBName = arr[arr.Length - 1].Replace(".MDF", ""); string DBFolder = arr[arr.Length - 2]; ServerConnection srvConn = new ServerConnection(sqlcon); SaveFileDialog saveBackupDialog = new SaveFileDialog(); Server srvSql = new Server(srvConn); string path = Application.StartupPath + @"\Data\DBBankCheque.mdf"; srvSql = new Server(srvConn); DateTime BackupDate = DateTime.Now; string BakDt = BackupDate.ToString("ddMMyyyhhmmss"); string FName = "Bank---" + DBFolder + "-" + BakDt + ".bak"; saveBackupDialog.FileName = FName; if (saveBackupDialog.ShowDialog() == DialogResult.OK) { Backup bkpDatabase = new Backup(); bkpDatabase.Action = BackupActionType.Database; bkpDatabase.Database = path; BackupDeviceItem bkpDevice = new BackupDeviceItem(saveBackupDialog.FileName, DeviceType.File); bkpDatabase.Devices.Add(bkpDevice); try { bkpDatabase.SqlBackup(srvSql); MessageBox.Show("The backup of database completed successfully ", "Bank", MessageBoxButtons.OK, MessageBoxIcon.Information); // MessageBoxes.messageBoxShow("The backup of database completed successfully"); } catch (Exception ex) { MessageBox.Show("Backup failed for Server . (Microsoft.SqlServer.Smo)", "Bank Software", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { sqlcon.Close(); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)