Catch SQL raise error in C#

RAISERRORs with a SEVERITY value under or equal to 10 are not caught on the C# side because I suppose they are considered just warnings as you can see from the
list at Database Engine Error Severities.

SEVERITY values between 11 and 16 are errors that can be corrected by the user, so, for example, you can try with:

RAISERROR('Already exist',16,1)

Otherwise, you could choose another error code from the list above or, if you really need it, prepare your own custom error message using sp_addmessage.

Leave a Comment