/// <summary>
/// 恢复数据库
///必须在Alter Database前加use master;否则用报错:
///用户必须在 master 数据库中。
///ALTER DATABASE 语句失败。
///因为数据库正在使用,所以未能获得对数据库的排它访问权。
///RESTORE DATABASE 操作异常终止。
///用户必须在 master 数据库中。
///ALTER DATABASE 语句失败。
/// </summary>
/// <param name="databaseName">数据库名称</param>
/// <param name="backPath">备份文件路径</param>
/// <returns></returns>
public bool ComeBack(string databaseName, string backPath)
{
bool result = false;
string sql = "use master Alter Database " + databaseName + " Set Offline with Rollback immediate;";
sql += "restore database " + databaseName + " from disk = '" ;
sql += backPath + "' ";
sql += "Alter Database " + databaseName + " Set OnLine With rollback Immediate;";
result = Execute(sql);
return(result);
}
/// <summary>
/// 备份数据库
/// </summary>
/// <param name="databaseName">数据库名称</param>
/// <param name="backPath">备份文件路径</param>
/// <returns></returns>
public bool Back(string databaseName, string backPath)
{
bool result = false;
string sql = "backup database " + databaseName + " to disk = '"
+ backPath + "'";
result = Execute(sql);
return(result);
}