title: Cannot detect SQL error when using ExecuteNonQuery()
body: <p>I have the following bit of code which runs a SQL statement:</p>
  
  <pre><code>int rowsEffected = 0;
  using (SqlConnection dbConnection = new SqlConnection(dbConnectionString))
  {
      try
      {
          dbConnection.InfoMessage += new SqlInfoMessageEventHandler(dbConnection_InfoMessage);
          dbConnection.FireInfoMessageEventOnUserErrors = true;
  
          dbConnection.Open();
  
  
          SqlCommand command = dbConnection.CreateCommand();
          command.CommandTimeout = 0;
          command.CommandText = sqlStatement;
  
          rowsEffected = command.ExecuteNonQuery();
      }
      catch (Exception e)
      {
          // Handle exception
      }
  }
  </code></pre>
  
  <p>Long running SQL statements can report progress via the SqlInfoMessageEventHandler by raising an error using RAISERROR with the appropriate severity value.</p>
  
  <p>The reasons for setting FireInfoMessageEventOnUserErrors to true is because, without this, all the messages from the SQL statement are only processed all at once when ExecuteNonQuery() returns. With this value set to true, the progress messages are processed as they are raised by the SQL statement.</p>
  
  <p>As the name of the property suggests, the event handler also fires upon errors and not just on the specific severity level reserved for progress feedback by the SQL statement.</p>
  
  <p>The event handler for the progress feedback looks like this:</p>
  
  <pre><code>public void dbConnection_InfoMessage(object sender, SqlInfoMessageEventArgs e)
  {
      if (e.Errors.Count &gt; 0)
      {
          throw new Exception("Something bad happened");
      }
  
      // Report progress
  }
  </code></pre>
  
  <p>As you can see, I can detect when an error occurs by the property within 'e' but throwing the exception doesn't do anything. I was hoping execution would drop into the catch block but this isn't the case.</p>
  
  <p>How can I get determine after the ExcecuteNonQuery() method that an error occurred?</p>
  
  <p>TIA</p>