Subject Re: [firebird-support] Action on disconnect
Author Daniel Berstein
I think a better aproach would be to:

1) Create your log table with these three fields: connection, last_alive, disconnection.

2) On start of your application insert connection timestamp into fields "connection" and
"last_alive".

3) After some elapsed time your application updates the "last_alive" field with the
current timestamp.

4) On disconection, your application log the timestamp in the "disconnection" field.

5) Periodically (perhaps on a trigger from steps 2, 3 or 4), you could check your log
table to identify all rows where [now - "last_alive"] is greater than the elapsed time your
application is configured to update the "last_alive" field. Rows that match the above
criteria are probably those that loose the connection unexpectedly, so you may just
update the "disconnection" field with the last known value of last_alive. Statistically I
belive a much proper value would be ["last_alive" + (update_last_alive_timeout / 2)].

In other words, if you maintain a "last_alive" field, you can estimate the disconnection
time of your client application if it's disconnected abnormally.

Regards,
Daniel Berstein.


On 12 Sep 2003 at 15:09, Jonathan Neve wrote:

> Helen Borrie wrote:
>
> >>I've asked this on the Interbase newsgroup, and they say it's not
> >>possible. Can this be done with FireBird? If not, wouldn't this be a
> >>useful (and simple) thing to implement?
> >>
> >>
> >
> >I don't know. What would be trapped? Who or what would trap it? What
> >would the purpose be?
> >
> Well, it would open a door of new possibilities. For example, I have an
> application in which I log all user connections and disconnections to
> the database. The way I do it is insert a row into a log table when the
> application starts up, and at shutdown, I update the record with the
> disconnection time. My problem is that when a user's connection to the
> database gets cut without the application having been closed properly
> (for example if the application hangs, or if there's a network problem),
> I have no way of updating the record, so it looks like the user is still
> connected.
>
> So it would be nice if there was a way to trap database events (such as
> connection and disconnection) in a sort of trigger style. Something like:
>
> CREATE TRIGGER ON_CONNECTION_LOST BEFORE (or AFTER) DISCONNECT
> AS
> BEGIN
> ......
> END;
>
> Perhaps there could also be a way to catch this event from a client
> application, but this seems to me to be less useful.
>
> Thanks!
>
> Jonathan Neve.
>
>
> [Non-text portions of this message have been removed]
>
>
>
> To unsubscribe from this group, send an email to:
> firebird-support-unsubscribe@yahoogroups.com
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>