Subject Reconnecting in a windows service
Author havard_o

Apologies if I do any mistakes or if this is a FAQ (if so I haven't
found it :). I've got a Windows service which connects to a firebird
database. To do this I'm currently using a TIB_Connection. I've got a
guard clause procedure which does the following:
if conn.Connected then
Result := true

below this I've tried various exception handling but the Connect call
always throws an exception which "lands" way outside this procedure.
My service needs to have a valid connection before it can do any
processing and so what I need to do is:
1. Check for connection
2. If no valid connection, sleep and try to reconnect.
3. If valid connection continue and do the work.

What is the best way to do this? I saw the OnError event mentioned on
this forum but since I'm fairly new to Delphi I don't know how to use
this. Are there other objects I should use instead of the
TIB_Connection? I have to mention that my service uses a couple of
threads but my thread syncronization seems to work nicely when the
connection is up and valid. Since I know that the server that the
service will run on have dodgy connection lines I should ideally be
able to handle a broken connection in the middle of the processing
also, but this is secondary.

Any help is highly appreciated!