E B via SQLMonster.com (fo***@SQLMonster.com) writes:
how to handle sql errors with severity less then 10 in .NET
i call to stored procedure which raise error with severity 10 for example
however in c# i can't cach this error (with severiry >= 11 it going to the
catch block in my c# app), also the @@ERROR is equal to zero when severity
<= 10
You set up an InfoMessages event handler. Please see the .Net Framework
reference for details.
In SqlClient 2.0, there is a new property which permits you divert all
errors with severity <= 16, that is all user errors, to the InfoMessage
handler. This actually has a couple of advantages, particulary when
you use ExecuteReader, so there is all reason to get used to InfoMessages.
By the way, a small tidbit: you can never get a message with severity
10 from SQL Server. 10 is always changed to level 0.
--
Erland Sommarskog, SQL Server MVP,
es****@sommarskog.se
Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp