I inherited code that looks like this:
Saved procedure UpdateSomeStuff
Update Table1 Set Col1=Para@1
IF @@Error > 0 Goto ERR
Update Table2 Set Col1=Para@2
IF @@Error > 0 Goto ERR
RETURN 0
ERR:
return -1;
This sp is called by ADO.NET in C #, like this
try
{
myCommand.ExecuteNonQuery();
}
catch (System.Exception ex)
{
_log.Error(ex);
throw();
}
finally
{
if(myConnection!=null)
{
myConnection.Close();
}
}
I just ask myself: is there a part of IF @@ Error> 0 Going to ERR is good for anything? If an error occurs, sp will be returned anyway, and an exception will be detected in the calling method.
The calling code does not handle the return value of 0 and -1. My plan would be to remove all Error Handlers in the Stored Procedure and have the same result. Am I right or is there something I missed?
source
share