Questions tagged [raiserror]
The raiserror tag has no usage guidance.
23
questions
0
votes
1
answer
59
views
Distinguish errors I raise from other SQL Server errors
In my stored procedures, when a business rule is broken I raise an error that bubbles up to the C# client app and gets displayed to the user. e.g.
RAISERROR('Hey, you cannot do that because blah blah ...
1
vote
1
answer
102
views
Error Severity 16 Alert being raised for events where is_event_logged = 0
I have an error level 16 alert set up as follows:
USE [msdb]
GO
EXEC msdb.dbo.sp_add_alert @name=N'Error - Severity 16',
@message_id=0,
@severity=16,
@enabled=1,
@...
0
votes
1
answer
48
views
SQL Server 2019: Rasing errors between 1 and 13000
I've been struggling with a task which requires me to raise a number of errors for testing purposes. Of course the time consuming errors are between 1 and 13000. I've managed to do them, but I need to ...
3
votes
1
answer
216
views
SSMS / SQL-Server delays console output (RAISEERROR WITH NOWAIT)
It is well known, that SSMS (or maybe the SQL Server, but I'd guess more the SSMS) delays PRINT messages until several lines (40) are gathered in the buffer, before they are really printed to the ...
0
votes
1
answer
270
views
how to convert from raiserror to throw in the current context?
I have a function that checks is the file is present on disk in an specific location.
Using that function I am checking for the latest backup, in the code below.
If we don't have a backup anymore, ...
0
votes
3
answers
584
views
Deprecated raiserror detection
I want to upgrade SQL server from 2008 to 2014 versiyon. I checked all of the deprecated features including raiserror syntax. But I have many stored procedures to check. Some of them use new syntax, ...
5
votes
2
answers
4k
views
raise an error in sql server severity higher than 18
I can easily raise user defined errors where severity is not higher than 18. When is higher, I get this error
Error severity levels greater than 18 can only be specified by members of the
...
0
votes
0
answers
2k
views
SQL Server - What is the RAISERROR substitution parameter for boolean/bit type?
I'd like to quickly dump some context into an error message including some boolean flags using the handy-dandy substitution parameters of RAISERROR such as
CREATE PROCEDURE MyProc
(
@param1 INT = ...
0
votes
1
answer
392
views
How can I RAISE_APPLICATION_ERROR and do an INSERT in the same trigger?
From what I see, having the RAISE_APPLICATION_ERROR cancels the other operations that I would have in the trigger. I tried writing first the INSERT and then the RAISE_APPLICATION_ERROR hoping that ...
2
votes
1
answer
420
views
Behavior of case sensitivity of RAISERROR when run remotely
I have a remote SQL Server that I can connect to using a local instance of SSMS.
When raising errors, we use
RAISERROR( 'This works', 16, -1 )
Remotely, this works fine if it's all uppercase, or ...
6
votes
2
answers
5k
views
How do I create a SQL Agent Alert on a custom error message in SQL Server 2012?
I want operators to be notified when I throw a custom error message. My understanding is that I need to add a message to sys.messages, then I can either RAISERROR or THROW that error ID. Creating an ...
0
votes
0
answers
178
views
The best way to raise error from mass insert query
I have a following stored procedure:
CREATE TABLE Table1 (val INT)
GO
CREATE TABLE Table2 (val INT)
GO
ALTER TABLE Table1 ADD CONSTRAINT chk1 CHECK (val > 0 )
GO
INSERT INTO Table2
SELECT 1 UNION ...
2
votes
1
answer
6k
views
RAISERROR on a trigger. What will happen? Will we get informed?
What will happen if a trigger on a table hits the part of the trigger that includes the RAISERROR code below?
RAISERROR('Attempt to modify supposedly immutable number.',16,1)
How will we know this ...
0
votes
1
answer
106
views
MySql Insert signal if where clause fails
As part of a chained sequence of transactional queries, I'm inserting values that exist in a temporary table into a new table.
Every query is validated for errors in PHP using:
if (!mysqli_query($...
1
vote
1
answer
18k
views
Behaviour of RAISERROR within a TRY/CATCH within a loop
I have just encountered a section of SQL that is behaving not as I would expect (See below for a distilled version of the SQL in question that demonstrates the problem pattern).
(This is on SQL ...
9
votes
1
answer
5k
views
How to conditionally raise an error in MySQL without stored procedure
I need to conditionally raise an error, but I can only use a simple statement and no stored procedure.
I'd like to do something like this:
select case when foo = "bar" then 1 else SIGNAL SQLSTATE '...
2
votes
1
answer
640
views
Raising an Alert with THROW
It seems to me that SQL THROW is missing a crucial feature that RAISERROR has, and that is the abilty to use WITH LOG so that an Alert can be fired when the error number is logged in the Application ...
0
votes
0
answers
726
views
Oracle force job to fail via raise_application_error
I have a business-flow consisting of several steps implemented as stored procedures in Oracle. I want wrap the whole flow, which is linear (Step1 -> Step2 -> Step3 ->...) into a job that will run ...
12
votes
4
answers
10k
views
How to escape '%' inside varchar @params for RAISERROR funcion in SQL Server 2012
How I should escape the % character in params so my RAISERROR retun my message
declare @msg varchar(max) = (SELECT ' Message with % ' AS MSG)
if @msg is not null
begin
RAISERROR (@msg ,16,1);
...
0
votes
1
answer
7k
views
RaiseError on SQL Server stored procedures
ALTER PROCEDURE sp1
as
begin
IF (@PersonId=0)
RAISERROR(N'Error already raised. See previous errors.', 16, 1);
break
end
I want something like the following.
If no value in the variable, how ...
2
votes
0
answers
132
views
What to do when the error message is longer than 4000 in T-SQL?
I have a OPENQUERY linking to an Oracle server that is failing. (I can't make any changes on the oracle server)
But when it returns the error string it is cut short because it returns the query in ...
4
votes
1
answer
2k
views
Is it possible to return a custom error for a logon trigger?
I'm trying to get a logon trigger to return a custom error. Thus far everything I have tried causes it to return the standard error:
My trigger looks like this:
CREATE TRIGGER Test_Logon_Trigger
ON ...
3
votes
1
answer
3k
views
Is it possible to raiserror within a For Delete Trigger that rolls back the deletes
There is a claim at the end of this accepted answer that if an error occurs within a "For Delete" trigger, the delete action would be rolled back because it is part of an implicit transaction.
...