Detection of database connection lost

Detection of database connection lost

Postby Feneck91 » Mon 11 Jul 2016 15:34

I develop an application that listen the database tables to reflect database changes.

It's work well. Unfortunally the server is automatically reboot each sunday at 3:00 am.
How can I detect the connection lost ?

You detect it because I have exceptions :
Exception thrown: 'Devart.Common.k' in Devart.Data.PostgreSql.dll
Exception thrown: 'Devart.Data.PostgreSql.PgSqlException' in Devart.Data.PostgreSql.dll
Exception thrown: 'Devart.Common.k' in Devart.Data.PostgreSql.dll
Exception thrown: 'Devart.Data.PostgreSql.PgSqlException' in Devart.Data.PostgreSql.dll
Exception thrown: 'Devart.Common.k' in Devart.Data.PostgreSql.dll
Exception thrown: 'Devart.Data.PostgreSql.PgSqlException' in Devart.Data.PostgreSql.dll
Exception thrown: 'Devart.Common.k' in Devart.Data.PostgreSql.dll
Exception thrown: 'Devart.Data.PostgreSql.PgSqlException' in Devart.Data.PostgreSql.dll
Exception thrown: 'Devart.Common.k' in Devart.Data.PostgreSql.dll
.....

I use a PgSqlConnection and an Alerter like :

Code: Select all
    Alerter = new PgSqlAlerter(_pgsqlConnection, $"_tableToSurvey.TableName}_create_update_delete_event");
Alerter.Stopped += OnAlerterStopped;


The OnAlerterStopped is never called when database service is stopped !
A way to get a notification ?
Feneck91
 
Posts: 37
Joined: Mon 12 Aug 2013 13:52

Re: Detection of database connection lost

Postby Pinturiccio » Fri 15 Jul 2016 14:07

The Stopped event in a PgSqlAlert object is called when you stop the alerting. When a connection is lost, the Stopped event is not called. Instead, the Error event is called. If you get this event after the connection loss, you will need to create alerter again, because you need to re-initialize listening for a new session. So you need to stop listening the lost session, create a new one and start a new alert when you get this event.

For more information please refer to https://www.devart.com/dotconnect/postgresql/docs/?Devart.Data.PostgreSql~Devart.Data.PostgreSql.PgSqlAlerter~Error_EV.html
Pinturiccio
Devart Team
 
Posts: 1983
Joined: Wed 02 Nov 2011 09:44


Return to dotConnect for PostgreSQL