raiserror

Stored Procs - Best way to pass messages back to user application

I'd like know what people think about using RAISERROR in stored procedures to pass back user messages (i.e. business related messages, not error messages) to the application. Some of the senior developers in my firm have been using this method and catching the SqlException in our C# code to pick up the messages and display them to the...

How to display error message generated from raiserror() with SQL Server

I am interacting with SQL Server 2005 from a jsp via JDBC (this is an assignment not a real project) and I have created a trigger in the database I am using. If a certain condition is not met when this trigger executes I raise an error via raiserror(). I would like this error to be displayed on the actual page that calls the SQL Server q...

Formatting RAISERROR messages in SYBASE ASE 12.5

In a stored procedure, I am trying to test if a parameter is null or less then 1, and if so, raise an error with a friendly message, and the value of the parameter. Here is my code: IF @ID IS NULL OR @ID <= 0 BEGIN RAISERROR 27001 'ID is ?????. ID cannot be null or less then zero.' RETURN 27001 END What I would like back is e...

What do the different RAISERROR severity levels mean?

My best google result was this: below 11 are warnings, not errors 11-16 are available for use above 16 are system errors there is no behavioral difference among 11-16 But, from BOL, "Severity levels from 0 through 18 can be specified by any user." In my particular stored procedure, I want the error returned to a .Net client applicat...

TRY and RAISERROR in T-SQL

Having a small issue and wondering if I'm using these correctly. In my SQL script is have BEGIN TRY // check some information and if there are certains errors RAISERROR ('Errors found, please fix these errors and retry', 1, 2) WITH SETERROR // Complete normal process if no errors encountered above PRINT 'IMPORT SUCCEED...

SQL Statment Termination using RAISERROR

(SQL 2005) Is it possible for a raiserror to terminate a stored proc. For example, in a large system we've got a value that wasn't expected being entered into a specific column. In an update trigger if you write: if exists (select * from inserted where testcol = 7) begin raiseerror('My Custom Error', 16, 1) end the update informati...

Ruby Web API scraping / error handling with Hpricot

I have written a simple ruby gem to scrape a set of websites, providing a simple API, inside the gem itself I have included a retry method... to attempt to use Hpricot 3 or more times on failure mostly due to timeouts. def retryable(options = {}, &block) opts = { :tries => 1, :on => Exception }.merge(options) retry_exception, retri...

Raiserror in procedure (SQL Server 2005) is not caught in update process in client side(c#)

Hi all, I am using stored procedure with RAISERROR. The error raised by the SP is not caught by the try catch statement in c#.Net. I'm using SqlDataSource for SQL connection and SqlDataSource_Updating event to update the data. SQL Code: DECLARE @count int @count=0 if(@count = 0) begin RAISERROR('Updation failed. record alread...

Accessing RAISEERROR message from cfstoredproc

Hi there, I have a SQL stored procedure which under some situations will return a result of -1 if it fails, but also returns a message via the RAISERROR command e.g.: BEGIN RAISERROR ('Error %i has occurred', 11, 1, 0) RETURN -1 END I am accessing this via coldfusion using cfstoredproc e.g.: <cfstoredproc procedure="sp_ret...

sql raiseerror error.number wrong in VB

I wrote a T-SQL query which includes a test for valid EmployeeNo. If the EmployeeNo is not valid, I do the following: RAISERROR(5005, 10, 1, N'Invalid Employee No') return @@Error Back in VB.Net I test the sql exception and found that when the Employee No is invalid the error.number is not 5005 as I would expect, but 2732. What is th...

T-SQL: How can i use RAISERROR for Informational Output Without Causing Script To Error?

Okay so i've got a stored proc which does a bunch of things (not important). Now, the stored proc is quite verbose, it prints out a lot of things (progress, rowcounts, etc). As you all know, using PRINT with variables is extremely painful (requiring you to have a CAST party). So, ive used RAISERROR to print these friendly messages (ev...

T-SQL - Return custom error message and end query

I have a lengthy stored procedure in which I would like to do something like the following: IF @SubPageDirectory IS NULL BEGIN RAISERROR('@SubPageDirectory cannot be NULL', 10, 1) EXIT STORED PROCEDURE END Basically I wish to check whether my variable is NULL, and if it is, return an error message to my .NET Web Application, a...