【发布时间】:2018-06-30 18:55:54
【问题描述】:
我正在尝试在将新数据添加到数据库时调用一个函数。
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.org/doc/wait.html
...Npgsql will only process it and emit an event to the user the next time a command is sent and processed。你能检查它是否适合你吗? -
不相关,但把它放在
using块中,那么你就不需要finally
标签: c# sql postgresql triggers