Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Sql Server Programming

What does "RaiseError" do?


Hi,

Inside a stored procedure, there sometimes is a statement called
"RaiseError". An example is below:

                IF @lsSystemParamValue IS NULL
        BEGIN
                RAISERROR ('Parameter ''%s'' was NULL.',16,1,@SystemParamName)
                GOTO ErrorHandler
        END

Can anyone tell me what the "RaiseError" statement does in a non-
jargon language?

Thanks!

Basically, it throws an error back to the calling program.  This way, the
calling program can check for errors and determine what to do from there.
For example, SQL Server will raise an error 1205 if there is a deadlock.
The usual response is for the client to re-try, if you so choose.
Therefore, your client app should check the value of the error code for a
1205.

You can add error messages to the SQL Server instance with sp_addmessage.
If you raise and error without an error code - as in your example - then the
error number is 50000.

--
   Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON   Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau

"Curious" <fir5tsi@yahoo.com> wrote in message

news:1181000422.252185.255730@p47g2000hsd.googlegroups.com...
Hi,

Inside a stored procedure, there sometimes is a statement called
"RaiseError". An example is below:

                IF @lsSystemParamValue IS NULL
BEGIN
RAISERROR ('Parameter ''%s'' was NULL.',16,1,@SystemParamName)
GOTO ErrorHandler
END

Can anyone tell me what the "RaiseError" statement does in a non-
jargon language?

Thanks!

-----------------------------------------------Reply-----------------------------------------------

Hi Tom,

So it's equivalent to a "throw" statement? Will the calling routine
also get the text message in "RaiseError"?

-----------------------------------------------Reply-----------------------------------------------

Yes, it will.  You can even pick up the severity.

--
   Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON   Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau

"Curious" <fir5tsi@yahoo.com> wrote in message

news:1181007215.266939.207880@h2g2000hsg.googlegroups.com...
Hi Tom,

So it's equivalent to a "throw" statement? Will the calling routine
also get the text message in "RaiseError"?

-----------------------------------------------Reply-----------------------------------------------

On Jun 5, 2:33 am, Curious <fir5tsi@yahoo.com> wrote:

> Hi Tom,

> So it's equivalent to a "throw" statement? Will the calling routine
> also get the text message in "RaiseError"?

It's not really the equivalent of throw, since the procedure will
continue to execute after the RAISERROR statement - and may have
further RAISERRORs, or do anything else it chooses to.

Damien

-----------------------------------------------Reply-----------------------------------------------

That's a good point.  For that reason, your client app should go through the
entire collection of errors to ensure you picked up everything that went
wrong.

--
   Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA, MCITP, MCTS
SQL Server MVP
Toronto, ON   Canada
https://mvp.support.microsoft.com/profile/Tom.Moreau

"Damien" <Damien_The_Unbelie@hotmail.com> wrote in message

news:1181028763.311093.153640@h2g2000hsg.googlegroups.com...
On Jun 5, 2:33 am, Curious <fir5tsi@yahoo.com> wrote:

> Hi Tom,

> So it's equivalent to a "throw" statement? Will the calling routine
> also get the text message in "RaiseError"?

It's not really the equivalent of throw, since the procedure will
continue to execute after the RAISERROR statement - and may have
further RAISERRORs, or do anything else it chooses to.

Damien

-----------------------------------------------Reply-----------------------------------------------

How can a client application pick up all of the errors raised in a
stored procedure? In what type of syntax?

-----------------------------------------------Reply-----------------------------------------------
Well, it depends on the client application, what language it's written in,
and how it interfaces with the database (e.g. ODBC, OLEDB, etc).

--
Aaron Bertrand
SQL Server MVP
http://www.sqlblog.com/
http://www.aspfaq.com/5006

"Curious" <fir5tsi@yahoo.com> wrote in message

news:1181058053.074047.206300@q75g2000hsh.googlegroups.com...

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc