ADOQuery TimeOut with try except

379 views Asked by At

I have an ADOQuery and a ADOConnection on the form , the simplified code looks like this :

on Form.Create I simply give ADOConnection the connection parameters and make sure it is closed. After this I never open ADOConnection directly , it happens only via the ADOQuery .

try
 if ADOQuery.Active then ADOQuery.Close;
 ADOQuery.Open;
except
 Application.Terminate;
end;

I would expect this code to catch all manner of Exceptions (like a ADOQuery Timeout) and simply terminate the application.

Somehow I still receive a Query Timeout Exceeded . (But perhaps it is comming from ADOConnection itself ?) I am not 100% sure .

if I would do it like this would it solve the problem :

try
 if ADOConnection.Connected:=true then ADOConnection.Close;

 if ADOQuery.Active then ADOQuery.Close;
 ADOQuery.Open;
except
 Application.Terminate;
end;

Thank you.

UPDATE

The question is :

this is not Catching Query Timeout because the AdoConnection which it uses is not inside the try except block ? ( I don't really see any other reason )

In this example bellow ADOConnection1 is Connected on first ADOQuery.Open and stays like that till the software is done.

try
 if ADOQuery.Active then ADOQuery.Close;
 ADOQuery.Open;
except
 Application.Terminate;
end;

This except does not seem to catch all Query Timeouts...

1

There are 1 answers

0
R. Hoek On

You are using a Form on which these components are placed right.

So check if the Connected property of the TADOConnection is true in the IDE...

Now, make sure it’s ALWAYS false, because when you create the form, this property wil ‘activate/open’ the connection before the OnCreate event is fired.