3

目前,我正在使用NPGSQL连接器将 PostgreSQL 数据库与我用VB.Net.

我尝试使用 PostgreSQL和功能NOTIFY将特定表的表更改到前端。我从那次尝试中得到了积极的结果。我成功地得到了从后端到前端的通知。为了实现这一点,我尝试了以下方法:LISTENNOTIFY

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

这工作正常,但是,PostgreSQL 有一个全新的功能来通知通知可以有一个有效负载,比如NOTIFY test, 'Hello world'(其中 Hello world 是有效负载,换句话说,附加信息)。

我想在 Notification 事件处理程序中获取该附加信息NotificationSupportHelper。因此,为了得到它,我只是尝试访问NpgsqlNotificationEventArgs. 但是我在那次尝试中失败了,因为它只包含 PID 和 Condition 作为其成员。所以我决定看一下NPGQL 文档,从那里,我知道,没有办法在 NPGSQL 版本 1.0 中获得更多信息。但是他们在他们的第二个版本(NPGSQL V 2.0)中为NpgsqlNotificationEventArgs称为AdditionalInformation提供了一个额外的成员。但它目前也在建设中。此属性将始终返回 String.Empty(来自文档)。

所以我希望你们理解我想要完成的事情,我只需要在有人提出payload的时候在前端接收notification。有人知道如何达到我的要求吗?是否有任何其他connector可用而不是有效地在前端NPGSQL处理notification event,这意味着payload在前端获得。

4

1 回答 1

1

万一其他人有这个问题。AdditionalInformation现在有房源。

Private Sub NotificationSupportHelper(ByVal sender As Object,
                                  ByVal e As NpgsqlNotificationEventArgs)
    MsgBox(e.Condition & " " & e.AdditionalInformation)
End Sub
于 2017-03-08T12:33:52.457 回答