日期:2014-05-18  浏览次数:20412 次

(急求)SQLDMO在C#中的差异备份还原问题
用SQLDMO组件实现全还原正常,但要实现差异备份的还原应该怎么做?
下面是C#代码的全还原,但如果文件为差异备份即出错
C# code


    SQLDMO.Restore oRestore = new SQLDMO.RestoreClass();//创建还原对象
    SQLDMO.SQLServer oSQLServer = new SQLDMO.SQLServerClass();//创建服务对象
    try
    {
        oSQLServer.LoginSecure = false;
        oSQLServer.Connect("localhost\\sqlexpress", "sa", "sa");//连接数据服务
        SQLDMO.QueryResults qr = oSQLServer.EnumProcesses(-1);//查询该数据库正在连接的进程
        int iColPIDNum = -1;
        int iColDbName = -1;
        for (int i = 1; i <= qr.Columns; i++)
        {
            string strName = qr.get_ColumnName(i);
            if (strName.ToUpper().Trim() == "SPID")
            {
                iColPIDNum = i;
            }
            else if (strName.ToUpper().Trim() == "DBNAME")
            {
                iColDbName = i;
            }
            if (iColPIDNum != -1 && iColDbName != -1)
                break;
        }
        for (int i = 1; i <= qr.Rows; i++)
        {
            int IPID = qr.GetColumnLong(i, iColPIDNum);
            string strDbName = qr.GetColumnString(i, iColDbName);
            if (strDbName.ToUpper().Trim() == "mm_gis_intmap".ToUpper())
            {
                oSQLServer.KillProcess(IPID);//kill正在连接的进程
            }
        }

        oRestore.Action = SQLDMO.SQLDMO_RESTORE_TYPE.SQLDMORestore_Database;
        oRestore.Database = "mm_gis_intmap";
        oRestore.Files = @"C:\mm_gis_intmap\mmgt_t.bak";//设置数据备份文件,如果该文件是完全备份,运行OK,差异备份即不行
        //oRestore.StandbyFiles = @"C:\mm_gis_intmap\mmgt_t1.bak";
        oRestore.FileNumber = 1;
        oRestore.ReplaceDatabase = true;
        oRestore.SQLRestore(oSQLServer);
    }
    catch
    {
        throw;
    }
    finally
    {
        oSQLServer.DisConnect();
    }




------解决方案--------------------
给出什么错误?
没用c#应用过dmo,vb,asp都试过dmo的差异备份没问题的
实在不行考虑一下smo吧
------解决方案--------------------
如果是全备先还原 最后要加

with norecovery