Discussion:
Auto Re-Connection
(too old to reply)
Russell
2008-06-12 11:31:09 UTC
Permalink
I have a remote server with a TSQLConnection with keep connection = true. If
the connection is idle it the server (Firebird 2) disconnects and I then get
an exception the next time the app tries to run a query. Is there a way that
I can trap the exception and then reconnect? I could do this on a query by
quey basis but as there are a lot I'd rather implement a generic catch on
the connection if I could.

Thanks
yannis
2008-06-12 11:47:49 UTC
Permalink
Post by Russell
I have a remote server with a TSQLConnection with keep connection =
true. If the connection is idle it the server (Firebird 2)
disconnects and I then get an exception the next time the app tries
to run a query. Is there a way that I can trap the exception and then
reconnect? I could do this on a query by quey basis but as there are
a lot I'd rather implement a generic catch on the connection if I
could.
Thanks
what I have done in a similar case (using ADO and MS SQL) I have
written an onBeforeExecute event on the connection where I would
execute something trivial eg

try
MainConnection.execute('select Getdate()')
except
on e:Exception do
begin
MainConnection.Connected := false
mainConnection.Connected := true;
end;
end;

if the connection was droped for any reason it would reconnect again if
the connection was not available (eg server down, network problems etc)
an exception would be raised.

Ofcourse this is a minimal example to get you started,
you could extend it with some kind of timing mechanism to run the check
only if the time passed since the last command is bigger than a
threshold eg 10 minutes.

regards
Yannis.
--

Loading...