Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Catching Exception in Async TADOQuery

Status
Not open for further replies.

NiMuSi

Technical User
Mar 23, 2019
2
0
0
GB
Hi All,

I am using Delphi 2010 to run Asynchronous queries.

whosrdaddy's code example from thread102-1764605 allows me to cancel long running queries. I now need to catch exceptions in my Async ADOQuery. For example, if I run this query "SELECT * FROM NotATable" (where the table does not exist), should exit with the message invalid object name, but the app just hangs. The message only shows once I stop the app. The same thing happens with a timeout.

How can I capture these events, ie there is an error in the SQL or a timeout has occurred?

Grateful for any advice,
NiMuSi
 
Hi NiMusi,

you can add an OnExecuteComplete eventhandler to your TADOConnection object:

Code:
procedure TForm1.ADOConnection1ExecuteComplete(Connection: TADOConnection; RecordsAffected: Integer; const Error: Error;
                                               var EventStatus: TEventStatus; const Command: _Command; const Recordset: _Recordset);
begin
 if EventStatus = esErrorsOccured then
  begin
   memo1.Lines.add(Error.Description);
   // recover from error
   Button1.Caption := 'Start';
   Button1.Tag := 0;
  end;
end;

-----------------------------------------------------
Helping people is my job...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top