DELPHI编程用SQLDMO呈现带进度条的SQL Server数据库Databnse备份!

假如写成线程方法效果更好,共享!
先导入SQLDMO生成SQLDMO_TLB.pas文档

unit Unit3;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,SQLDMO_TLB, StdCtrls, ComCtrls,comobj;

type
TForm3 = class(TForm)
Button1: TButton;
ProgressBar1: TProgressBar;
procedure Button1Click(Sender: TObject);

private
{ Private declarations }
public

{ Public declarations }
end;

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;
end;

var
Form3: TForm3;
implementation

{$R *.dfm}

function TBackupSink.PercentComplete(const Message: WideString; Percent: Integer):HResult;
begin
Form3.ProgressBar1.Position:=percent;
result:=0;
end;

function TBackupSink.NextMedia(const Message: WideString):HResult;
begin
result:=-1;
end;

function TBackupSink.Complete(const Message: WideString):HResult;
begin
result:=1;
end;


procedure TForm3.Button1Click(Sender: TObject);
var
Mysql数据库Server:SQLServer;
MyBackUp:BackUp2;
MyBackSink:TBackupSink;
FInterfaceConnection:integer;
BS:TBackupSink;
begin
BS:=TBackupSink.Create;
Mysql数据库Server:=coSQLServer.Create;
MyBackUp:=coBackUp2.Create;
Mysql数据库Server.Connect('192.169.1.10','sa','password');;
MyBackUp.Database:='DBA';
MyBackUp.Initialize:=true;
MyBackUp.PercentCompleteNotification:=1;
MyBackUp.Action:=0;//0完整备份,1差异备份,2文档组备份,3日志备份
MyBackUp.Files:='d:\dba.bak';
InterfaceConnect(MyBackUp, IID_BackupSink, BS, FInterfaceConnection);//关键是那里
MyBackUp.SQLBackup (Mysql数据库Server);
InterfaceDisconnect(MyBackUp, IID_BackupSink,FInterfaceConnection);//
end;

end.

+++++++++++++++++++++++++++++++++++
backupsink就在SQLDMO_TLB.pas里,定义了接口!
抄唯一

打开DELPHI编程,Project菜单->Import Type Library...,在列表框中找到"Microsoft SQLDMO Object
Library(Version 8.0)"(你的版本估计和我的不相同),能够看到Class names列表框中呈现出相应的类,
由于很多类名与vcl本身的类名冲突(比如TApplication,TTable等),需求改正类的名字,不过不改也没联系,
那里假设没改,点击按钮"Create Unit",进入漫长的等待过程。由于生成的文档较量大(6万多行的代码Code,
2.46M),那个过程很简易被误以为死机,稍候片刻。
第二步,改正Type Library文档。
经过漫长的等待,终于得到了来之不易的SQLDMO_TLB.pas,然而,当咱们Compile的时候却发明那个单元
无法编译,提示大意为ID重复定义,那个简单,把第二个ID改成xID,编译经过。
posted @ 2012-02-22 19:24  leon_kin  阅读(424)  评论(0编辑  收藏  举报