Capture Stored Procedure print output in .NET
You can do this by adding an event handler to the InfoMessage event on the connection.
myConnection.InfoMessage += new SqlInfoMessageEventHandler(myConnection_InfoMessage);
void myConnection_InfoMessage(object sender, SqlInfoMessageEventArgs e)
{
Console.WriteLine(e.Message);
}
This is really handy if you want to capture Print output in LinqPad's output console:
SqlConnection conn = new SqlConnection(ConnectionString);
//anonymous function to dump print statements to output console
conn.InfoMessage += (object obj, SqlInfoMessageEventArgs e)=>{
e.Message.Dump();
};