Page 1 of 1

Detection of database connection lost

Posted: Mon 11 Jul 2016 15:34
by Feneck91
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 ?

Re: Detection of database connection lost

Posted: Fri 15 Jul 2016 14:07
by Pinturiccio
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