我做了个SQL server数据库备份小程序,想做个进度条

limitanger 2005-10-26 10:00:15
我做了个SQL server数据库备份小程序,想做个进度条,因为数据库比较大,备份的时候如果没有进度条提示,就象死机似的
...全文
296 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xjp_1999 2006-04-03
  • 打赏
  • 举报
回复
收藏
  • 打赏
  • 举报
回复
to oushengfen(逸帆) ( ) 信誉:88
收了
superyys 2005-10-26
  • 打赏
  • 举报
回复
楼上的是好东东,收藏
oushengfen 2005-10-26
  • 打赏
  • 举报
回复
用SQLDMO对象来做是可以的。
在http://dev.csdn.net/article/67303.shtm中有关于SQLDMO的导入;

有一个DELPHI下的SQL备份控件,能显示备份的百分数,也就可以做进度条。
unit SQLBackup;

interface

uses
Windows, Messages, SysUtils, Classes,SQLDMO_TLB,SQLDMO_Command,ActiveX,ComObj,Forms;

type
TPercentCompleteEvent=procedure(Message: String;Percent:Integer) of object;
TMessageEvent=procedure(Message:String) of object;
TBackupMode= (FullDatabase, Differential);
TSQLBackup = class(TComponent)
private
FServerName: String; //数据库服务器名称
FdatabaseName:String; //数据库名称
FLoginTimeout:Integer;//登陆延时
FBackupMode:TBackupMode;//备份数据模式
FOnPercentComplete: TPercentCompleteEvent;
FOnNextMedia: TMessageEvent;
FOnComplete: TMessageEvent;
oSQLServer:_SQLServer;
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent);
destructor Destroy;override;
procedure Connect(UserName:String;Password:String); overload;
procedure Disconnect;
procedure SQLBackup (FileName:String);
property ServerName:String read FServerName write FServerName;
property DataBaseName:String read FdataBaseName write FDatabaseName;
property LoginTimeout:Integer read FLoginTimeout write FLoginTimeout default 30;
property BackupMode:TBackupMode read FBackupMode write FBackupMode;
property PercentComplete:TPercentCompleteEvent read FOnPercentComplete write FOnPercentComplete;
property NextMedia:TMessageEvent read FOnNextMedia write FOnNextMedia;
property Complete:TMessageEvent read FOnComplete write FOnComplete;
published
{ Published declarations }

end;

TBackupSink=class (TInterfacedObject,BackupSink)
private
function PercentComplete(const Message: WideString; Percent: Integer): HResult; stdcall;
function NextMedia(const Message: WideString): HResult; stdcall;
function Complete(const Message: WideString): HResult; stdcall;
public
SQLBackup: TSQLBackup;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TSQLBackup]);
end;

{ TSQLBackup }

procedure TSQLBackup.Connect(UserName, Password: String);
begin
try
osqlServer.LoginSecure :=False;
osqlServer.LoginTimeout :=FLoginTimeout;
osqlServer.Connect(FServerName,userName,Password);
except
Raise;
end;
end;

constructor TSQLBackup.Create(AOwner: TComponent);
begin
try
inherited create(AOwner);
osqlServer :=coSqlServer.Create;
oSqlServer._AddRef;
except
Raise;
end;

end;

destructor TSQLBackup.Destroy;
begin
OSqlServer._Release;
osqlServer :=nil;
inherited Destroy;
end;

procedure TSQLBackup.Disconnect;
begin
try
osqlServer.DisConnect;
except
Raise;
end;
end;

procedure TSQLBackup.SQLBackup(FileName: String);
var
obackup :_backUp;
oBackupSink :TBackupSink;
ConnectionPoint:IConnectionPoint;
dwCookie:Integer;
ConnectionPointContainer :IConnectionPointContainer;
begin
try
obackup := cobackup.Create;
obackup._AddRef;
obackup.Database :=FDataBaseName;
if FBackupMode=FullDatabase then
obackup.Action :=SQLDMOBackup_Database
else
obackup.Action :=SQLDMOBackup_Differential;
obackup.Files :=FileName;
oBackupSink :=TBackupSink.Create;
oBackupSink._AddRef;
obackupsink.SQLBackup :=self;
obackup.QueryInterface(IConnectionPointContainer,ConnectionPointContainer);
ConnectionPointContainer._AddRef;
ConnectionPointContainer.FindConnectionPoint(BackupSink,ConnectionPoint);
ConnectionPoint._AddRef;
ConnectionPoint.Advise(oBackupSink,dwCookie);
application.ProcessMessages;
obackup.SQLBackup(oSqlServer);
ConnectionPoint.Unadvise(dwCookie);
obackup._Release;
obackup :=nil;
oBackupSink._Release;
oBackupSink :=nil;
ConnectionPoint._Release;
ConnectionPoint :=nil;
ConnectionPointContainer._Release;
ConnectionPointContainer :=nil;
application.ProcessMessages;
except
Raise;
end;
end;


{ TBackupSink }

function TBackupSink.Complete(const Message: WideString): HResult;
begin
try
SQLBackup.Complete(message);
except
Raise;
end;
end;

function TBackupSink.NextMedia(const Message: WideString): HResult;
begin
try
SQLBackup.NextMedia(message);
except
Raise;
end;

end;

function TBackupSink.PercentComplete(const Message: WideString;
Percent: Integer): HResult;
begin
try
SQLBackup.PercentComplete(message,Percent);
except
Raise;
end;
end;

end.
aiirii 2005-10-26
  • 打赏
  • 举报
回复
有个sql server 的 COM 组件,可以实现回调,但在delphi试验不出, 用vb, c#就可, 奇怪
yanlls 2005-10-26
  • 打赏
  • 举报
回复
估计只能作个假的
9807146wang 2005-10-26
  • 打赏
  • 举报
回复
用进度条控件就可以了,然后设置step=1,还有spID吧

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧