Notify, Listen Docs or example

Notify, Listen Docs or example

Postby twynne » Tue 18 Nov 2008 14:20

I'm having a hard time finding information on how to implement the Notify/Listen with .connect for PostgreSQL. Is there a sample that shows this or if there is something in the documentation could you please post a link? Thanks
Posts: 1
Joined: Tue 18 Nov 2008 14:17

Postby Shalex » Fri 21 Nov 2008 10:50

Here is a sample that demonstrates using Listening with dotConnect for PostgreSQL.
Code: Select all
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Devart.Data;
using Devart.Data.PostgreSql;
using System.Threading;

namespace NotifyListenPG {
  public partial class Form1 : Form {
    public Form1() {

    System.Threading.Timer timer;
    PgSqlConnection connection;

    private void Form1_Load(object sender, EventArgs e) {
      connection = new PgSqlConnection();
      connection.ConnectionString = "host=localhost; user id=postgres; password=postgres; database=test; schema=public;";

      connection.Notification += new PgSqlNotificationEventHandler(ConnectionNotification);
      PgSqlCommand listenCommand = new PgSqlCommand("listen \"listen_point\"", connection);

       TimerCallback timerDelegate = new TimerCallback(Check);
       timer = new System.Threading.Timer(timerDelegate, null, 1000, 3000);
    private void ConnectionNotification(object sender, PgSqlNotificationEventArgs e) {
       string s = e.Condition;
       if (s != null && s == "listen_point") {
         // TODO: this code will be executed
    private void Check(Object stateInfo) {
      //some command should be executed to check the notification
      PgSqlCommand listenCommand = new PgSqlCommand("select 1", connection);

Execute "notify "listen_point"" at the server side to check this code.
Devart Team
Posts: 7888
Joined: Thu 14 Aug 2008 12:44

Return to dotConnect for PostgreSQL