0
我有一个简单的应用程序来备份和还原SQL Server 2014数据库。在还原SQL Server数据库之前比较模式
这里是我的代码:
public void BackUp(BackUpManifest backUpManifest)
{
try
{
using (SqlConnection cnn = new SqlConnection(backUpManifest.ConnectionString))
{
cnn.Open();
ServerConnection sc = new ServerConnection(cnn);
Server sv = new Server(sc);
// Create backup device item for the backup
BackupDeviceItem bdi = new BackupDeviceItem(backUpManifest.SavedPath, DeviceType.File);
// Create the backup information
var bk = new Backup();
bk.Devices.Add(bdi);
bk.Action = BackupActionType.Database;
bk.BackupSetDescription = backUpManifest.SetDescription;
bk.BackupSetName = backUpManifest.Name;
bk.Database = cnn.Database;
bk.ExpirationDate = new DateTime(2007, 5, 1);
bk.LogTruncation = BackupTruncateLogType.Truncate;
// Run the backup
bk.SqlBackup(sv);
}
}
catch (Exception ex)
{
throw ex;
}
}
public void Restore(BackUpManifest backUpManifest)
{
try
{
using (SqlConnection cnn = new SqlConnection(backUpManifest.ConnectionString))
{
cnn.Open();
cnn.ChangeDatabase("master");
ServerConnection sc = new ServerConnection(cnn);
Server sv = new Server(sc);
sv.KillAllProcesses(backUpManifest.Name);
// Create backup device item for the backup
BackupDeviceItem bdi = new BackupDeviceItem(backUpManifest.SavedPath, DeviceType.File);
// Create the restore object
Restore resDB = new Restore();
resDB.Devices.Add(bdi);
resDB.NoRecovery = false;
resDB.ReplaceDatabase = true;
resDB.Database = backUpManifest.Name;
resDB.ReplaceDatabase = true;
// Restore the database
resDB.SqlRestore(sv);
}
}
catch(Exception ex)
{
throw ex;
}
}
现在我的情况是,如果数据库已被修改 - 即添加/编辑/修改列/表的话,我不想让数据库恢复。
是否有无论如何我可以比较现有数据库的架构,我试图恢复与?
感谢