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#:
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
RAISERRORif you don’tRETURNdirectly afterwards. If you don’t return, you can get multiple errors back.