c# - 从 postgres 取回消息

标签 c# postgresql npgsql

我正在从 C# 可执行文件中启动 postgres 中的真空进程。我希望消息返回到我的可执行文件,但我无法从输出窗口取回消息。

简而言之,我正在使用 NPGSQL 在 postgres 中寻找与此等效的内容,例如:

// Display messages this code is for SQL server to reteive data back from message tab

conn.InfoMessage += delegate(object sender, SqlInfoMessageEventArgs e) {
  stdmForm.txtLastSQLMessages.Text +`=` "\n" + e.Message;
};

我想使用 NPGSQL 在我的 C# 代码中获取此消息。

最佳答案

我尝试了下面的代码。它会给你完整的执行日志。从这里我只是解析了我需要的日志。这不是最好的方法,但我找不到其他方法。

//log the Vacuum command information
NpgsqlEventLog.Level = LogLevel.Debug;
NpgsqlEventLog.LogName = VacuumLogFilePath + "rolling.log"; 
NpgsqlEventLog.EchoMessages = false;

try
{
    //Run the Vacuum Command
    NpgsqlCommand comm = new NpgsqlCommand("VACUUM VERBOSE ANALYZE", connection); 
    comm.ExecuteNonQuery();

}

关于c# - 从 postgres 取回消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17753038/

相关文章:

node.js - Knex 不会结束连接 Postgres

php - 无法使用数据类型时间戳将日期输入到 postgres 字段中

java - 如何使用 Hibernate Criteria 在 Postgresql JSON 中进行搜索并与 Lateral 一起使用

postgresql - 如果超过 6 列,Azure 数据工厂复制管道将失败

C# 枚举到 postgres 枚举

c# - WinfForms 带边框的最大化窗口无隐藏任务栏

c# - UWP 应用程序在启动时崩溃

c# - 如果 NodaTime 使用 Duration 而 Postgres 使用 INTERVAL/Period,如何在 EF Core 中进行时间戳运算?

c# - 序列化数据表以供以后重用

c# - 如何在 Java 客户端的 WCF 服务中使用 C#-Properties