I have a database table trigger that can RAISERROR at multiple point of the code.
I know that we can add some custom arguments along with the RAISERROR calls (I think that those parameters are mainly for setting a custom error message).
All of this is fine.
On the .Net part of the code (C# for me), when I catch the related error, everything is almost fine, I can get it's custom message, state, severity...
... but I'm still struggling to get back my custom parameters from this C# SqlException object and I failed to find information after a long research.
My questions are :
- Is it possible to recover those parameters directly from the
SqlException? (without having to parse the generated error message) - If possible, how to get them ? Where are they hidding inside the exception object?
Thank you.
Finally, I found a solution.
I'm now forgetting to pass custom parameters through the T-Sql
Raiserrorand I directly get the entity on error and all its values thanks to the parent exception of typeDbUpdateException(in my case) which contains anEntriescollection with my full entity on error.I just need to cast that generic type into my real entity model and I'm good to go.
Thanks.