I would like to print messages from an SQL stored procedure.
If I execture with the SYNC parameter cmd.ExecuteNonQuery the connection raises the InfoMessage event, but when I execute with the ASYNC option, the event does not fire.
Is there a reason I don't get events when executed in ASYNC?
Here is my code:
class Program { static string connstring = "data source = xyz;initial catalog = abc;user id=abc;password=abc;Asynchronous Processing=True"; static void Main(string[] args) { SqlConnection conn = new SqlConnection(connstring); conn.InfoMessage += new SqlInfoMessageEventHandler(conn_InfoMessage); SqlCommand cmd = new SqlCommand("TMP_PROC", conn); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@TMP_ID", 1); try { Console.WriteLine("connection open"); conn.Open(); Console.WriteLine("executing query");
source share