Raising SQL errors

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am building an asp.net website which uses a SQL Server database. I want to
do data validation in the stored procedures and triggers, and raise SQL
Server errors there when a user enters invalid data. The message that is
displayed to the user (like "ABC is an invalid Product Code") should be
written in the stored procedure or trigger and then bubbled up to the client
app.

Does anyone have any advice on best practices or able to direct me to some
link / article that can help ?

Thanks, Craig
 
The best practice is to do data validation while the data is still with your
client. If you do not want to do it on client, then make up error codes on
Sproc and return the appropriate error code.

John
 
You need to use a RAISERROR statement in SQL Server. In this case you can
register specific exceptions and raise them when specific conditions occur
(errors or just "stuff happened"). You can also use PRINT messages and other
techniques like OUTPUT parameters.

I'll be discussing all of these alternatives in detail at my workshop held
in Montreal (if there is still room) on the 18th (this Saturday). See my web
site for details on the DevTeach conference.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
www.sqlreportingservices.net
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
Back
Top