Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Good practice of returning error from store proc
Message
From
24/05/2012 15:01:36
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01544314
Message ID:
01544324
Views:
18
>>>>Hi,
>>>>
>>>>In my VFP stored procedures I always returned a string; empty if no problem occurred; or the string would have a description of the error, if a problem occurred.
>>>>
>>>>In SQL Server stored procedures, I learned today, I can only return an integer. I am thinking about returning 0 if no problem and -1 if there is a problem. Then, if there is a problem, set to an OUTPUT parameter the value of error message. I am wondering if this would be a good practice? My concern is that then each and every stored procedure would have to have an OUTPUT parameter.
>>>>
>>>>I would appreciate any suggestions on this topic. TIA.
>>>
>>>I think the best practice is to send the error back as an error and deal with that exception on the client side. You'll get all the info. Alternatively, catch that error in SQL Server and pass back to the client with some extra error info you may find desirable. See samples in my SP:
>>>How to insert information into multiple related tables and return ID using SQLDataSource
>>>
>>>It shows how to trap the error and pass the error back to the client.
>>
>>Do I understand correctly that the OUTPUT parameter (as a way to return an error description) is not a good approach (in your opinion)? But instead call RAISERROR ('Error description ...')?
>
>Yes. I don't think it's a good idea in general to return an error as OUTPUT parameter, although there may be cases when this is the desired approach. For most cases I'd say we need to handle errors in the calling application.

Thank you. I like this approach (with RAISERROR) so I don't have to rely on the OUTPUT.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform