I have a procedure which does some logic and raises an error if a condition has been fulfilled. This procedure is made in SQL Server and is called from .NET Core. This is the part where the RAISEERROR
is written.
IF @tmp_cnt < @ent_cnt
BEGIN
DECLARE @msg AS NVARCHAR(MAX) = CONCAT('Not all of the selected entities are eligible for change. Will be changed for ',
CAST(@tmp_cnt AS NVARCHAR(50)), ' out of the selected ', CAST(@ent_cnt AS NVARCHAR(50)), ' entities.')
RAISERROR(@msg, 15, 1)
END
print 'Set FII.IsCurrent = 0'
UPDATE fii
The error should be raised but the procedure should keep doing its stuff i.e. this print
statement should print out. However, when I catch the error in .NET, I get this print
value as well. How do I handle it on a .NET side? This is the way I do it
catch (SqlException e)
{
return BadRequest(e.Message);
}
Said so, when I reach this catch
block, the error I get is Not all of the selected entities are ligible for change... \r\nSet FII.IsCurrent = 0
. What is noticeable here is that this SqlException
logs both the RAISEERROR
and print
but my goal is to only get the value from RAISEERROR
. How could I do this?