Questions tagged [raiserror]
138 questions
82
votes
2 answers
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…

Steve S.
- 931
- 1
- 8
- 7
33
votes
3 answers
How to print DateTime variable in the RAISERROR method?
My Stored Procedure accepts two params
@EffectiveStartDate DATETIME
@EffectiveEndDate DATETIME
I wrote the validation code as this:
IF(@EffectiveStartDate > @EffectiveEndDate)
BEGIN
RAISERROR ('SPName:…

vinayvasyani
- 1,393
- 4
- 13
- 34
32
votes
3 answers
Catch SQL raise error in C#
I generate the raise error in SQL procedure:
RAISERROR('Already exist',-10,-10)
but I can not catch it using the following code in C#
catch (SqlException ex)
{
bResult = false;
if (ex.Errors[0].Number == -10)
{
…

Raed Alsaleh
- 1,581
- 9
- 27
- 50
29
votes
7 answers
How to simulate a deadlock in SQL Server in a single process?
Our client side code detects deadlocks, waits for an interval, then retries the request up to 5 times. The retry logic detects the deadlocks based on the error number 1205.
My goal is to test both the deadlock retry logic and deadlock handling…

Paul Williams
- 16,585
- 5
- 47
- 82
20
votes
1 answer
TSQL RaiseError incorrect syntax, following MSDN's guidelines
MSDN states the following syntax:
RAISERROR ( { msg_id | msg_str | @local_variable }
{ ,severity ,state }
[ ,argument [ ,...n ] ] )
[ WITH option [ ,...n ] ]
The msg_str expects a string up to 2047 characters but truncates longer strings. It…

Aske B.
- 6,419
- 8
- 35
- 62
20
votes
3 answers
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…

StevenMcD
- 17,262
- 11
- 42
- 54
18
votes
4 answers
Raise custom error message with RAISERROR in SQL Server
In previous versions we raised errors in t-sql like:
RAISERROR 50000 'My Error Message'
In the latest SQL Server this syntax has been discontinued and replace with the RaiseError () syntax.
I would like to have a generic method of raising errors,…

Cameron Castillo
- 2,712
- 10
- 47
- 77
15
votes
4 answers
How to use variables in SQL raiserror
I am trying to show my int variables in raiserror @MaxAmount and @MinAmount
Raiserror('Total Amount should be less than %s and Greater than %s',16,1,@MaxAmount,@MinAmount)
But Im getting error:
Must declare the scalar variable "@MaxAmount".

Nuke
- 1,169
- 5
- 16
- 33
11
votes
4 answers
RAISERROR within Case statement
Can you not raise errors within a case statement in T-SQL? I always have problems with SQL case statements :/
begin try
declare @i int
--set @i = (select COUNT(1) from table_name)
select Item_Num =
CASE (select COUNT(1)…

Nyra
- 859
- 1
- 7
- 27
10
votes
2 answers
RAISERROR―How to distinguish with SqlException?
I have some 3-4 stored procedures ― which I can modify if needed ― that use RAISERROR to inform my application of some fatal errors on the database side. Some of these stored procedures are executed from the C# side with ExecuteNonQuery, while…

User
- 3,244
- 8
- 27
- 48
10
votes
1 answer
Raising an exception while using numba
Following up from here, I keep getting overflows. So I'm trying to raise an exception so that I know exactly what's going wrong where.
I've got something like this:
@jit
def train_function(X, y, H):
np.seterr(over="raise", under="raise",…

user961627
- 12,379
- 42
- 136
- 210
9
votes
1 answer
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…

Curtis
- 101,612
- 66
- 270
- 352
8
votes
1 answer
Trigger with a RAISERROR and ELSE case issue
I am trying to make a bit of code that takes in 2 separate columns, a month and a year. From there I want it to see if those numbers entered have already passed or not. If they have passed, cause an error to pass and stop the transaction. Otherwise,…

MikeyZ
- 105
- 1
- 1
- 6
6
votes
14 answers
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…

HAdes
- 16,713
- 22
- 58
- 74
5
votes
1 answer
Is there a scalable alternative to SQL Server Query Notifications for raising events in an application from SQL Server?
SQL Server Query Notifications is a great tool, but it doesn't seem built to scale very well. Every application that wants/needs notifications has to keep an open connection to the database for the duration of the time it wants notifications…

richard
- 12,263
- 23
- 95
- 151