c# - 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 参数名称:关键字'
我究竟做错了什么?
谢谢
解决方案
我使用的是最新版本的 NPGSQL,3.6.2(我认为),而另一个项目使用的是 2.11.96 版本。由于使用旧版本,该程序可以正常工作。我猜较新的 NPGSQL 使用不同的方式来执行触发功能。
推荐阅读
- python - 当输入文件以空格分隔时,如何替换熊猫中的空格填充单元格?
- vertica - 如何优化 union all 语句
- c# - 如果自签名清单,C# 无法在 Azure 管道中传递构建
- c# - 在 Service 中注入模拟的 dbContext - 集成测试
- android - Best alternative for object keyword in kotlin
- javascript - 使用 Codelabs 教程通过 Cloud Functions 访问 Gmail API
- php - Codeigniter 允许使用法语 uri 字符
- javascript - 如何在各种不同的 JavaScript 环境中对 ISO 时间集合进行排序?
- c# - 删除 'DF_ETable_EDate__######' 对象以将 DateTime 转换为 DateTime2
- html - 删除移动视图中不必要的边距