關于 [分享:实现带进度条的数据库备份] 的問題(100分)

  • 主题发起人 主题发起人 goodbobi
  • 开始时间 开始时间
G

goodbobi

Unregistered / Unconfirmed
GUEST, unregistred user!
按照這個貼子<br>http://www.delphibbs.com/delphibbs/dispq.asp?lid=3330303<br><br>问题:分享:实现带进度条的数据库备份!(SQL Server) ( 积分:0, 回复:46, 阅读:1356 )<br>分类:数据库-C/S型 ( 版主:qince, luyear ) &nbsp;<br>来自:yitang, 时间:2006-1-16 13:48:00, ID:3330303 <br><br>請問有誰寫出了恢複的程序呀.我改了一下.同一台電腦恢複可以,拿到另一台恢複就不行了,報錯:<br>[SQL-DMO]您必須指定備份或還原的備份裝置<br>代碼如下:<br>procedure TFM_Main.SpeedButton2Click(Sender: TObject);<br>var<br> &nbsp;MySQLServer: SQLServer;<br> &nbsp;MyRestore: Restore2;<br> &nbsp;FInterfaceConnection: integer;<br> &nbsp;BS:TRestoreSink;<br>begin<br> &nbsp;if EdtResPath.Text = '' then begin<br> &nbsp; &nbsp;Forms.Application.MessageBox('請選擇您的恢複路徑!', '提示', MB_OK+MB_ICONINFORMATION);<br> &nbsp; &nbsp;EdtResPath.SetFocus;<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br> &nbsp;if EdtResServerName.Text = '' then begin<br> &nbsp; &nbsp;Forms.Application.MessageBox('請輸入你的服務器名稱!', '提示', MB_OK+MB_ICONINFORMATION);<br> &nbsp; &nbsp;EdtResServerName.SetFocus;<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br> &nbsp;if EdtResDatabaseName.Text = '' then begin<br> &nbsp; &nbsp;Forms.Application.MessageBox('請輸入你的資料庫名稱!', '提示', MB_OK+MB_ICONINFORMATION);<br> &nbsp; &nbsp;EdtResDatabaseName.SetFocus;<br> &nbsp; &nbsp;Exit;<br> &nbsp;end;<br> &nbsp;if Forms.Application.MessageBox(PChar('您確認要恢復資料庫'+EdtResDatabaseName.Text+'嗎?'#13#13'此操作會將數據恢復到備份時的狀態, 請慎重處理!'),'確認', MB_YESNO+MB_ICONQUESTION) = IDNO then<br> &nbsp; &nbsp;exit;<br> &nbsp;try<br> &nbsp; &nbsp;Forms.Application.ProcessMessages;<br> &nbsp; &nbsp;BS:=TRestoreSink.Create;<br> &nbsp; &nbsp;MySQLServer := coSQLServer.Create;<br> &nbsp; &nbsp;MyRestore := coRestore2.Create;<br> &nbsp; &nbsp;MySQLServer.Connect(EdtResServerName.Text, ConUserName, ConPassword); &nbsp;//連接信息<br> &nbsp; &nbsp;MyRestore.Database := EdtResDatabaseName.Text; &nbsp;//資料庫名稱<br> &nbsp; &nbsp;MyRestore.Files := GetShortName(ExtractFilePath(EdtBakPath.Text)) + ExtractFileName(EdtBakPath.Text); &nbsp;//恢複路徑<br> &nbsp;// &nbsp;MyRestore.Initialize := true;<br> &nbsp; &nbsp;MyRestore.PercentCompleteNotification := 1;<br> &nbsp; &nbsp;MyRestore.Action := 0; &nbsp;//0完整備份,1差異備份,2文件組備份,3日誌備份<br> &nbsp; &nbsp;InterfaceConnect(MyRestore, IID_RestoreSink, BS, FInterfaceConnection); &nbsp;//關鍵是這裏<br> &nbsp; &nbsp;MyRestore.SQLRestore(MySQLServer);<br> &nbsp; &nbsp;InterfaceDisconnect(MyRestore, IID_RestoreSink, FInterfaceConnection);<br> &nbsp; &nbsp;Forms.Application.MessageBox('資料庫恢複成功!', '成功', MB_OK+MB_ICONINFORMATION);<br> &nbsp; &nbsp;ProgressBar1.Position := 0;<br> &nbsp;except<br> &nbsp; &nbsp;on e: exception do<br> &nbsp; &nbsp; &nbsp;Forms.Application.MessageBox(PChar('資料庫恢複失敗!'#13#13+e.Message), '失敗', MB_OK+MB_ICONERROR);<br> &nbsp;end;<br>end;
 
那就是你这里指定的不对吧,<br> &nbsp; MyRestore.Files := GetShortName(ExtractFilePath(EdtBakPath.Text)) + ExtractFileName(EdtBakPath.Text); &nbsp;//恢複路徑
 
EdtBakPath,哈哈.謝謝!<br>是我弄錯了.應該是EdtResPath
 
多人接受答案了。
 
后退
顶部