RaiseErrors & ADO.NET

  • Thread starter Thread starter Sahil Malik
  • Start date Start date
Sahil Malik said:
What are your feelings about using RaiseErrors in stored procedures in an
ADO.NET world?

Any time an error condition occurs in a stored procedure without causing a
SQL Server error, you should return the error to the user with RAISERROR.

For instance, in this procedure an update matching 0 rows will not generate
a SQL Server error, but it does represent a real application error. Here
you should use RAISERROR.


create procedure t_update(@a int, @id int)
as
update t set a=@a where id=@id
if @@rowcount = 0
begin
raiserror('Row in T could not be found for updating',16,1)
return 1
end

David
 
Thanks for the help David. With your database knowledge I think I could get
a good answer.

Basically my question was centered around the practicality -
upsides/downsides of using RaiseError in ADO.NET.

So an upsides could be -

I can have exception handling (sort of) in TSQL.
I can batch my errors.
I can save network roundtrips and even control the client connections.

Downsides could be -
I can't find what row or column caused the error, unless I do string parsing
at the client.
... etc.?

... I was hoping someone who knew more than me could add a little flesh to
the bones.

- Sahil Malik
http://codebetter.com/blogs/sahil.malik/
 
Back
Top