Link to home
Start Free TrialLog in
Avatar of MrNet
MrNet

asked on

Progress Bar with SQL StoredProcedures!

Hi,

I am using Delphi 7 with MS-SQL 2000 to make softwares under Windows XP environment. I am using ADO connection to communicate with the SQL Server.

My application has some Stored Procedures which are doing long processes on the database. I want to show a progress bar while the procedure is running in the server side.

When I cal the StoredProcedure, there is one big loop is going to occure in it. Since this loop is not in Delphi, I am unable to show the progress bar.

Is there a way to figure out how to control the position of the progress bar while the StoredProcedure is running in the server side?

Regards,
Mr.Net
ASKER CERTIFIED SOLUTION
Avatar of kretzschmar
kretzschmar
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MrNet
MrNet

ASKER

Hi

Is there any sample Geo? I have no idea about running threads in delphi. I had created some of them using Visual Basic.Net. Could you please help me in this?

Regards,
Mr.Net
nice 'hack' geo ;) it might even use that someday :)
The question is.. if it's not a contraproductive slow down :))
But nice anyway :)

Kate
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The animation thing that Meikl suggested is also nice. I use that too sometimes but it's not very exact and if the stored procedure is a time consuming one... then the user MUST know the progress.
  I am using these methods... especially the first one combined with some text that I add from the same table in a memo... listbox everytime the progress is changed... something like:

ProgressBar.Position:=dm.qprogress.Fields['progres'];
Memo1.Lines.Add(dm.qprogress.Fields['comment']);

where "comment" is also a field in my table that is being also updated by the SP when the progress is changed. I place there comments like... " started updating table xxx with values" etc...

8-)
Calinutz
Hi,

Sorry for the delay. The following is an example of using a thread. Both TADODataSets use ADOConnection1, have CommandText and other properties set in design time. The usage of the returned dataset is not shown here.

In your case you'll need to use TADOCommand (for instance) instead of TADODataset in the thread and change the button.click event to do the following:
1. Set ProgressBar to 0
2. execute your SP instead of opening a dataset - it's in TDTSThread.Execute method actually
3. start a timer after DTSThread.Resume;
4. query the table created by the SP in Timer.OnTimer event and update the ProgressBar position

You may check Thread.Terminated property in the timer in order to be notified that the SP has finished. Something like:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  if Assigned(DTSThread) then begin
    if (DTSThread.Terminated) then begin
      ....

The example starts here:

type
  TForm1 = class(TForm)
    ADOConnection1: TADOConnection;
    dtsAccounts: TADODataSet;
    dtsClients: TADODataSet;
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    Button1: TButton;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TDTSThread = class(TThread)
    procedure Execute; override;
  private
    dts: TADODataSet;
  end;

var
  Form1: TForm1;
  DTSThread: TDTSThread;

implementation

{$R *.DFM}

procedure TDTSThread.Execute;
begin
  dts.Open;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  // TADODataset in a thread
  DTSThread := TDTSThread.Create(true); // suspended
  DTSThread.dts := dtsClients; // assign the component
  DTSThread.FreeOnTerminate := true; // free the thread automatically
  DTSThread.Resume; // start the thread
  // start the timer here
  Timer1.Enabled := true;

  // TADODataset in the main VCL thread
  dtsAccounts.Open;
end;

Regards, Geo
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial