如何使用代码备份SQL Server数据库
时间:2021-07-01 10:21:17
帮助过:2人阅读
Backup();
// Set the backup type to a database backup
bkpDatabase.Action =
BackupActionType.Database;
// Set the database that we want to perform a backup on
bkpDatabase.Database = DbName;
// cmbDatabase.SelectedItem.ToString();
// Set the backup device to a file
//new BackupDeviceItem(saveBackupDialog.FileName, DeviceType.File);
BackupDeviceItem bkpDevice =
new BackupDeviceItem(NewName, DeviceType.File);
// Add the backup device to the backup
bkpDatabase.Devices.Add(bkpDevice);
// Perform the backup
bkpDatabase.SqlBackup(SD.SrvSql);
File.Copy(Source, PathDestination +
"\\" +
fileName);
File.Delete(Source);
详细参见MSDN
https://msdn.microsoft.com/en-us/library/ms162133(v=sql.120).aspx
http://sridharbabuk.blogspot.com/2009/07/sql-server-database-backups-using-smo.html
如何使用代码备份SQL Server数据库
标签: