首页 > 解决方案 > Postgres C# 触发函数

问题描述

当新数据添加到数据库时,我试图调用一个函数。

NpgsqlConnection connListenRun = new NpgsqlConnection("Server=main;Port=5432;Database=netdb;UserId=postgres;Password=password;");
        try
        {
            connListenRun.Open();
            NpgsqlCommand cmd = new NpgsqlCommand("listen RunLogClient;", connListenRun);
            cmd.ExecuteNonQuery();
            connListenRun.Notification += new NotificationEventHandler(RunFinishNotification);
        }
        catch (NpgsqlException ex)
        {
            MessageBox.Show(ex.ToString());
        }
        finally
        {
            //connListen.Close();
        }

private void RunFinishNotification(object sender, NpgsqlNotificationEventArgs e)
    {
        MessageBox.Show("Data!");
    }

但是,当添加新数据时,我的消息框没有显示。在另一个使用相同触发函数的程序上具有“SyncNotification=true;” 在 conListenRun 结束时。

NpgsqlConnection connListenRun = new NpgsqlConnection("Server=main;Port=5432;Database=netdb;UserId=postgres;Password=password;SyncNotification=true;");

但是,当我输入 'SyncNotification=true;' 在声明中我收到此错误:

:'不支持关键字:syncnotification 参数名称:关键字'

我究竟做错了什么?

谢谢

标签: c#sqlpostgresqltriggers

解决方案


我使用的是最新版本的 NPGSQL,3.6.2(我认为),而另一个项目使用的是 2.11.96 版本。由于使用旧版本,该程序可以正常工作。我猜较新的 NPGSQL 使用不同的方式来执行触发功能。


推荐阅读