我正在尝试利用vb.netNotification中给出的事件。Npgsql我对这个机制有部分了解,我学到的是,当一个特定表的数据发生变化时,它trigger会被触发,所以trigger我们可以notify在前端了解data change.
我设法在我的前端运行以下代码
Public Sub test()
Dim conn = New NpgsqlConnection("Server=servername;port=portNo; _
User Id=UID;pwd=PWD;DataBase=DB;")
conn.Open()
Dim command = New NpgsqlCommand("listen notifytest;", conn)
command.ExecuteNonQuery()
AddHandler conn.Notification, AddressOf NotificationSupportHelper
command = New NpgsqlCommand("notify notifytest;", conn)
command.ExecuteNonQuery()
End Sub
Private Sub NotificationSupportHelper(ByVal sender As Object, _
ByVal e As NpgsqlNotificationEventArgs)
'Notified here.
End Sub
上面的代码没有任何问题。但是我想知道的是如何创建一个trigger关于notifies数据更改到前端的内容,结果Notification event我的前端被解雇了?我需要在哪里打电话listen?我需要调用listen每个查询的执行吗?任何机构都可以用一些示例代码来澄清我的疑问吗?