none
VB6中使用SQLDMO恢复差异备份和日志备份时出现错误 RRS feed

  • 问题

  •  Dim str     As String
              Dim ifExistDB     As Boolean
              On Error GoTo Handler
               
              '判断参数
              If sname = "" Or dbname = "" Then
                  MsgBox "服务器名称,数据库名称,不能为空!", vbInformation + vbOKOnly, "错误提示!"
                  Exit Sub
              End If
               
              '打开SQL-Server的连接
              Set oServer = New SQLDMO.SQLServer
              With oServer
                      .LoginSecure = True
                      .connect sname, username, password
              End With
               
              '新的SQL-DMO   的恢复对象
              Set Redb = New SQLDMO.Restore
              '启动事件
              'Set dmoRestoreEvent = dmoRestore
              Dim title As String
              Dim typestr As String    '判断是全备份、增量备份、日志备份的字符串
              title = Mid(filename, 1, Len(filename) - 4)
              typestr = Mid(title, Len(title) - 2, 3)
             
              If typestr = "All" Or typestr = "Dif" Then   '如果是全备份或差异备份则
                    Redb.Action = SQLDMORestore_Database
              End If
              If typestr = "Log" Then                      '如果是日志备份则
                    Redb.Action = SQLDMORestore_Log     
                
              End If
             
              Dim sourcefile As String   '要还原的数据库
              sourcefile = Text8.Text & "\" & Text6.Text
             
               
              With Redb
                      '恢复对象的数据库名称
                      .Database = dbname
                                    
                      '强制覆盖现有数据库
                       .ReplaceDatabase = True
                      '从文件中恢复
                      .Files = sourcefile           '恢复的文件路径和文件名
                      '匹配逻辑名称   和   物理名称(成对出现)                   
                      'str = "[test_DATA]" + "," + "[" + Trim(txtSQLPath.Text) + "\" + Trim(TxtDB.Text) + "_data.mdf]"
                      'str = str + ",[test_Log]" + "," + "[" + Trim(txtSQLPath.Text) + "\" + Trim(TxtDB.Text) + "_log.LDF]"
                                         
                       '.RelocateFiles = str
                   
                     
                     
               End With
                      '开始恢复
                      'Screen.MousePointer = vbHourglass
                      '.PercentCompleteNotification = 1
                     
                       
                       ProgressBar1.Value = 0
                       ProgressBar1.Max = 100
                       Screen.MousePointer = 0
                       DoEvents
                       Redb.SQLRestore oServer
                           
                          '下面Verify被恢复的数据库
                          Redb.SQLVerify oServer
                           
               
                           
                          '对象关闭
                          Set Redb = Nothing
                            oServer.disconnect
                          Set oServer = Nothing
                           
                          Screen.MousePointer = vbDefault
             
       
              Exit Sub
    Handler:
                         
              If Err.Number = -2147221499 Then
                      Resume Next
              Else
                      MsgBox Err.Number & vbCrLf & Err.Description
                      Screen.MousePointer = vbDefault
              End If




    出现如下错误:
     -2147217198
    先前的还原操作未指定WITH NORECOVERY  或 WITH STANDBY.
    请在除最后步骤之外的所有其他步骤中指定WITH NORECOVERY  或 WITH STANDBY后,重新启动该还原序列。
    RESTORE DATABASE 操作异常终止

    帮我看看,全备份能成功还原。差异备份,和日志备份都出现上面的错误。

    2009年6月17日 5:48

答案

  • 发觉用企业管理器也出现这个问题,只有恢复备份集才能一次把三个备份搞定,晕头了,实在不行,准备舍弃SQL-DMO,改用SQL语句去实现了

    2009年6月17日 8:13