Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Good practice of returning error from store proc
Message
 
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Environment versions
SQL Server:
SQL Server 2005
Miscellaneous
Thread ID:
01544314
Message ID:
01544317
Views:
26
>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.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform