Question

I am initiating a vacuum process in postgres from a C# executable. I want the message to be returned back to my executable, but i I'm not able to get the message back from output window.

In short, I'm looking for equivalent of this in postgres using NPGSQL like:

// 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;
};

I want to get this message in my C# code using NPGSQL.

Was it helpful?

Solution

I tried the code below. It will give you the complete execution log. From this I just parsed my required log. It's not the best way but I was not able to find anything else.

//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();

}

OTHER TIPS

Try the NpgsqlConnection.Notification event, which is PostgreSQL's counterpart to SqlConnection.InfoMessage. See here: archive of http://npgsql.projects.pgfoundry.org/docs/api/Npgsql.NpgsqlConnection.Notification.html.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top