I had not noticed the FireInfoMessageEventOnUserErrors property on the 2.0
Connection object before.
"When you set FireInfoMessageEventOnUserErrors to true, errors that were
previously treated as exceptions are now handled as InfoMessage events. All
events fire immediately and are handled by the event handler. If is
FireInfoMessageEventOnUserErrors is set to false, then InfoMessage events
are handled at the end of the procedure."
Adding the line
conn.FireInfoMessageEventOnUserErrors = True
right after the Using statement produced the following output.
And modifying
Private Sub conn_InfoMessage(ByVal sender As Object, ByVal e As
System.Data.SqlClient.SqlInfoMessageEventArgs)
Dim msg As New System.Text.StringBuilder
For Each sqlerr As SqlClient.SqlError In e.Errors
msg.AppendLine(sqlerr.LineNumber)
msg.AppendLine(sqlerr.Procedure)
msg.AppendLine(sqlerr.Message)
msg.AppendLine(sqlerr.Number)
msg.AppendLine(sqlerr.State)
Next
Trace.WriteLine(msg.ToString)
End Sub
does produce some valuable output. Thanks for the tip!
as far as C# goes, yes I do go both ways, the boss says that scope of
variables MUST be limited, so having module level conn objects would not be
a good idea
I also should have checked that conn is not nothing.