在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1.首先,要导入对象库定义: 打开Delphi,Project菜单->Import Type Library...,在列表框中找到"Microsoft SQLDMO Object 2.在窗体中加入一个进度条,将总进度设置为100(或在代码中设置)。 3.定义接口:
type
TBackupSink=class(TInterfacedobject,backupsink)//实现接口 function PercentComplete(const Message: WideString; Percent: Integer): HResult; stdcall; function NextMedia(const Message: WideString): HResult; stdcall; function Complete(const Message: WideString): HResult; stdcall;
4.实现
function TBackupSink.PercentComplete(const Message: WideString; Percent: Integer):HResult;
begin frmBackupDatabase.prgCompress.PartsComplete:=percent; result:=0; frmBackupDatabase.Refresh; Forms.Application.ProcessMessages; end; function TBackupSink.NextMedia(const Message: WideString):HResult; begin result:=-1; end; function TBackupSink.Complete(const Message: WideString):HResult; begin result:=1; messageBox(Forms.Application.handle,'成功备份数据!','提示信息',MB_ICONINFORMATION); end;
5.下面是备份按钮的操作
注意,引入的SQLDMO_TLB单元有许多类型定义和Delpgi冲突,如Application,建议在原Delphi的类型前加上限定,如Forms.Application。
procedure TfrmBackupDatabase.BackupDatabaseBySQLDMO;
var MySQLServer:SQLServer; MyBackUp:BackUp2; MyBackSink:TBackupSink; FInterfaceConnection:integer; BS:TBackupSink; begin prgCompress.TotalParts:=100; BS:=TBackupSink.Create; MySQLServer:=coSQLServer.Create; MyBackUp:=coBackUp2.Create; MySQLServer.Connect(DBServer,DBUser,DBPassword); MyBackUp.Database:=edtDatabaseName.Text; MyBackUp.Initialize:=true; MyBackUp.PercentCompleteNotification:=1; MyBackUp.Action:=0;//0完整备份,1差异备份,2文件组备份,3日志备份 MyBackUp.Files:=edtFileName.Text; InterfaceConnect(MyBackUp, IID_BackupSink, BS, FInterfaceConnection);//关键是这里 MyBackUp.SQLBackup (MySQLServer); InterfaceDisconnect(MyBackUp, IID_BackupSink,FInterfaceConnection);// end;
function TBackupSink.PercentComplete(const Message: WideString; Percent: Integer):HResult;
begin frmBackupDatabase.prgCompress.PartsComplete:=percent; result:=0; frmBackupDatabase.Refresh; Forms.Application.ProcessMessages; end; function TBackupSink.NextMedia(const Message: WideString):HResult; begin result:=-1; end; function TBackupSink.Complete(const Message: WideString):HResult; begin result:=1; messageBox(Forms.Application.handle,'成功备份数据!','提示信息',MB_ICONINFORMATION); end;
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论