【问题标题】:Get postgres messages through npgsql通过 npgsql 获取 postgres 消息
【发布时间】:2016-09-06 20:09:07
【问题描述】:

我的应用程序出现问题,我的要求之一是在调用 PLPGSQL 函数时捕获 postgres 中输出的消息,类似于此处发生的情况:

Get warning messages through psycopg2

除了我的问题在 npgsql 中。我设置了日志管理器:

NpgsqlLogManager.Provider = new ConsoleLoggingProvider(NpgsqlLogLevel.Trace, true, true);

我打这个电话:

_db.ExecuteScalar("SELECT test_warning();");

test_warning 是一个自定义的 sql 函数:

CREATE OR REPLACE FUNCTION test_warning()
  RETURNS void AS
$BODY$
begin
raise info 'this is only a test';
end; 
$BODY$
  LANGUAGE plpgsql VOLATILE;

_dbIDbConnection,并且使用Dapper 进行查询。在我的日志消息中,我只收到了对该函数的调用,以及其他一些连接信息:

DEBUG [40560] Opened connection to (Database Server)
TRACE [40560] Start user action
TRACE [40560] ExecuteNonScalar
DEBUG [40560] Executing statement(s):

                      SELECT test_warning()
TRACE [40560] End user action
TRACE [40560] Closing connection
TRACE [40560] Really closing connection
DEBUG [40560] Connection closed

没有提及警告/信息消息。

【问题讨论】:

标签: asp.net-mvc postgresql pgadmin


【解决方案1】:

首先,我会确保该函数存在...我启动了 postgres 并且无法运行该查询,所以它不是一个开箱即用的函数。

接下来,我会尝试调整我的通话方式...

_db.CommandText = "SELECT test_warning()";
_db.ExecuteScalar();

这是文档:http://www.npgsql.org/doc/index.html

【讨论】:

    猜你喜欢
    • 2013-07-19
    • 2013-04-02
    • 2018-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-13
    • 2020-05-04
    相关资源
    最近更新 更多