I am executing a command in this way :
var Command = new SqlCommand(cmdText, Connection, tr); Command.ExecuteNonQuery();
In the command there is an error, however .NET does not throw any error message. How could I know that the command did not executed properly, and how to get the exception?
You'll only get an exception in C# if your error's severity is 16 or above. If you are using a PRINT, you won't get an exception in .NET.
If you can edit the raise error code, this would cause a SqlException in C#:
RAISERROR('Some error message', 16, 1)
You can then get to each individual error in the SqlException.Errors collection.
Just a side-note - SQL Server will continue to run commands after the RAISERROR
if you don't RETURN
directly afterwards. If you don't return, you can get multiple errors back.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With