ado.net exception from raiserror

  • Thread starter Thread starter John
  • Start date Start date
J

John

In a couple of stored procedures (SQL Server 2000) im doing:

raiserror('aaa',16,1)
return 1

My understanding was that this should throw an exception in my C# code. But
sometimes it doesn't (I have to manually check the return value parameter).
Can anyone explain why?

Is there a difference in behaviour between SqlCommand.ExecuteNonQuery and
ExecuteReader (or SqlDataAdapter.Fill) in this regard? The situation where
I've noticed no exception is being thrown is when I'm calling
adapter.Fill(), and the sproc has already returned a resultset (but later on
in the sproc code it detects an error).

Maybe the presence of a resultset prevents an exception being thrown?

Thanks,

John
 
John said:
In a couple of stored procedures (SQL Server 2000) im doing:

raiserror('aaa',16,1)
return 1

My understanding was that this should throw an exception in my C# code.
But sometimes it doesn't (I have to manually check the return value
parameter). Can anyone explain why?

Is there a difference in behaviour between SqlCommand.ExecuteNonQuery and
ExecuteReader (or SqlDataAdapter.Fill) in this regard? The situation where
I've noticed no exception is being thrown is when I'm calling
adapter.Fill(), and the sproc has already returned a resultset (but later
on in the sproc code it detects an error).

Maybe the presence of a resultset prevents an exception being thrown?

Yes that is correct.

raiseerror just sends a message to the client (basically like print). The
sql client will check for messages before looking for a result set or output
parameters and will throw an exception if the severity of the message is too
high (12 I think). But if the message comes after the result set, then it
will probably ignore it.

David
 
Back
Top