Connection InfoMessage Event Handler

How can I add a InfoMessage Event Handler to the current connection I'm using?

Something like this:

myConnection.InfoMessage += new SqlInfoMessageEventHandler(myConnection_InfoMessage);

void myConnection_InfoMessage(object sender, SqlInfoMessageEventArgs e)
{
myStringBuilderDefinedAsClassVariable.AppendLine(e.Message);
}

Comments

  • edited December 4
    You should be able to do this within the query:
    ((SqlConnection)Connection).InfoMessage += (sender, args) => args.Message.Dump();
    
    or:
    ((SqlConnection)Connection).InfoMessage += (sender, args) =>
        Util.SqlOutputWriter.WriteLine (args.Message);
    
  • great thanks!
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!