用sql还是smo,smo有进度可循;sql中用@@RowCount 获取结果。
用VS引用Interop.SQLDMO.dll 用里面方法还原就能得到
我以前写过一个备份的代码如下:
#region 数据库备份
public bool BackupDB(string url)
{
SQLDMO.Backup oBackup = new BackupClass();
SQLDMO.SQLServer oSQLServer = new SQLServerClass();
SqlConnection conn = SqlHelperEx.GetConnection();
try
{
oSQLServer.LoginSecure = false;
oSQLServer.Connect(CommonSystem.StringCut(conn.ConnectionString, "Data Source","Server"), CommonSystem.StringCut(conn.ConnectionString, "User Id", "uid"), CommonSystem.StringCut(conn.ConnectionString, "Password", "pwd"));
oBackup.Action = SQLDMO.SQLDMO_BACKUP_TYPE.SQLDMOBackup_Database;
oBackup.Database = CommonSystem.StringCut(conn.ConnectionString, "Initial Catalog");
oBackup.Files = url;
oBackup.BackupSetName = CommonSystem.StringCut(conn.ConnectionString, "Initial Catalog"); ;
oBackup.BackupSetDescription = "数据库备份";
oBackup.Initialize = true;
oBackup.SQLBackup(oSQLServer);
return true;
}
catch(Exception err)
{
PsLog.WriteLog(err.Message.ToString(), NLog.LogLevel.Error);
return false;
}
finally
{
oSQLServer.DisConnect();
}
}
#endregion