Detection of database connection lost

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
Feneck91
Posts: 50
Joined: Mon 12 Aug 2013 13:52

Detection of database connection lost

Post by 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 ?

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: Detection of database connection lost

Post by 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/postg ... or_EV.html

Post Reply