Subject Re: Reconnecting in a windows service
Author dmarmur2002
--- In, "havard_o" <havard_o@...> wrote:
> Hi,
> 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
> else
> begin
> try
> conn.Connect;
> 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.

No, FAQ, no (not that I know of). But an EXCELLENT example, sample, of
how to get an fully automated service that will disconnect gracefully
in any circumstance and reconnect when possible. Look at
Samples/NTService. You just have to replace the replication stuff with
what you are trying to do. I had to change one or two lines of code in
the base classes to get it running and there are some posts from me
that Jason (as usual *grump, grump* has deferred until... well) but
even if you consult those posts the problems might be mine entirely.
Mind that the sample is not runnable. Anyway it works like a charm
after a bit of tweaking. I can disconnect my server - do maintainance
and then bring it back on line without worrying about those services
lying around in different nooks and dusty corners. And it uses threads
- at least one. They (the services) will even refresh the metadata
cache as appropriate! I have FTS indexing services, replication
services for Outlook and groupwise and some other specialized stuff
lying around in different levels of quantity and quality at my clients
and the only thing that is a nuance after swithing to Jasons templates
are... well you guessed right - M$ Outlook. Keep of it if you can -
your life will be better. But that's another story.