SMO学习笔记(三)——效验数据库备份文件
在我们数据库做好备份之后,由于别的原因可能出现数据库备份文件损坏,这一篇介绍效验数据库备份文件的正确性。
SMO效验数据库备份文件代码:
SMO效验数据库备份文件代码:
/// <summary>
/// 效验数据库备份文件
/// </summary>
/// <param name="string"></param>
/// <returns></returns>
public static bool VerifyingBackups(string SqlSqlConnectionString, out string ErrorMessage)
{
using (SqlConnection Connection = new SqlConnection(SqlSqlConnectionString))
{
Server server = new Server(new ServerConnection(Connection));
Restore res = new Restore();
res.Devices.AddDevice(string.Format(@"{0}\{1}.{2}", "D:", "DB_BACK","bak"), DeviceType.File);
return res.SqlVerify(server, out ErrorMessage);
}
}
/// 效验数据库备份文件
/// </summary>
/// <param name="string"></param>
/// <returns></returns>
public static bool VerifyingBackups(string SqlSqlConnectionString, out string ErrorMessage)
{
using (SqlConnection Connection = new SqlConnection(SqlSqlConnectionString))
{
Server server = new Server(new ServerConnection(Connection));
Restore res = new Restore();
res.Devices.AddDevice(string.Format(@"{0}\{1}.{2}", "D:", "DB_BACK","bak"), DeviceType.File);
return res.SqlVerify(server, out ErrorMessage);
}
}