I am having an issue with SqlCommand class in C#. When I use ExecuteReader() on a T-SQL stored procedure that calls
RAISERROR() in a catch block the error does not get thrown in C#. I searched online and didn't find much but the one solution that I found that is pretty akward is to call NextResult() after done reading from tables.
Here is a simple example of what my SP is doing:
If you use ExecuteNonQuery () then the exception will come up but if you use ExecuteReader() it will not come up until you call NextResult().
Thanks,
Adam
RAISERROR() in a catch block the error does not get thrown in C#. I searched online and didn't find much but the one solution that I found that is pretty akward is to call NextResult() after done reading from tables.
Here is a simple example of what my SP is doing:
Code:
CREATE PROCEDURE [dbo].[test]
AS
BEGIN
DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
DECLARE @ErrorState INT;
BEGIN TRY
select 1 / 0
END TRY
BEGIN CATCH
SET @ErrorMessage = ERROR_MESSAGE();
SET @ErrorSeverity = ERROR_SEVERITY();
SET @ErrorState = ERROR_STATE();
RAISERROR (@ErrorMessage,@ErrorSeverity,@ErrorState);
END CATCH
END
Thanks,
Adam

Comment