首页 > 解决方案 > Npgsql - 通知事件并附加有效负载

问题描述

NOTIFY使用psql 方法时是否可以接收有效负载?

现在我正在使用

using (var cmd = new NpgsqlCommand("NOTIFY test", conn)) {
        cmd.ExecuteNonQuery();
}

但我想在NOTIFY活动中附上一条消息

澄清

using (var cmd = new NpgsqlCommand("NOTIFY test_channel, test_message", conn)) {
        cmd.ExecuteNonQuery();
}

这会引发错误

Exception has occurred: CLR/Npgsql.PostgresException
An exception of type 'Npgsql.PostgresException' 
occurred in System.Private.CoreLib.dll 
but was not handled in user code: 'External component has thrown an exception.'

标签: postgresqlasp.net-corenpgsql

解决方案


正如 PostgreSQL 文档所示,您可以包含任意有效负载字符串:

通知测试,有效载荷


推荐阅读