PgSQLAlerter on connection close

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
spliter
Posts: 6
Joined: Sun 16 Apr 2017 10:10

PgSQLAlerter on connection close

Post by spliter » Sun 16 Apr 2017 10:18

Hi,
i'm bit confused.

Code: Select all

    {
        PgSqlAlerter ZPgEventAlerter = new PgSqlAlerter();
        PgSqlConnection myConn = new PgSqlConnection();

        public Form1()
        {
            PgSqlConnectionStringBuilder builder = new PgSqlConnectionStringBuilder();
            builder.ConnectionString = "host=localhost;database=db;user id=postgres;password=postgres";
            builder.ApplicationName = "APP";

            myConn.ConnectionString = builder.ConnectionString;

            InitializeComponent();
            
            ZPgEventAlerter.Connection = myConn;
            
            ZPgEventAlerter.AlertNames = "shift_update";
            ZPgEventAlerter.Alert += ZPgEventAlerter_Alert; ;
            ZPgEventAlerter.Stopped += ZPgEventAlerter_Stopped;
            ZPgEventAlerter.Error += ZPgEventAlerter_Error;
            ZPgEventAlerter.Start();


            myConn.Open();
            //doing some select
            myConn.Close();
        }
After i started eventalerter, i normaly do some select or update, we open connection, so what we need, and then close connection. As i understand, connection isn't closed at all. After closed connection, i see that in postgres server are still two connections (one for alerter and one i created), but alerting isnt working anymore. If i comment out myConn.Close(); then it works. Also, there is nothing on those events raising Sopped and Error. So i dont get it, everything shows, that it should work, but its not working.
Thx for help!

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

Re: PgSQLAlerter on connection close

Post by Pinturiccio » Tue 18 Apr 2017 15:15

When you close the connection, the corresponding session is closed, and listening stops. Actually, you don’t need to open a connection manually for using PgSqlAlerter. The listening starts after the Start method call. But if you close the connection, the listening stops.

The Error event is not raised because there is no error, and the Stopped event is not raised because the Stop method wasn’t called.

If you use a PgSqlAlerter object, it’s better not to open or close the connection manually. If you want to work with this database, it’s better to create another connection and perform your commands via this new connection.
spliter wrote:After closed connection, i see that in postgres server are still two connections (one for alerter and one i created)
PgSqlConnection has the Pooling connection string parameter. If Pooling is set to true in the connection string (this is the default value), the physical connection is placed to the pool, when a connection object is closed.

spliter
Posts: 6
Joined: Sun 16 Apr 2017 10:10

Re: PgSQLAlerter on connection close

Post by spliter » Wed 19 Apr 2017 12:13

Thank you for clarification!

Post Reply