1

I'm having an issue on settin up SqlException.Number

On my Stored Proc i'm raising an error

--@number = 50001

RAISERROR(@number, 16, 1) -

I should expect that the Error_Number() should be @number but I always get 18054

Is there something wrong with my RAISERROR?

2 Answers 2

3

Check the sys.messages table for error code 74601. if this is a user defined error, it shouold be added in the table.

for any error that is greater than 50000 should give you this output if not found.

Msg 18054, Level 16, State 1, Line 1
Error XXXXX, severity 16, state 1 was raised, but no message with that error number was found in sys.messages. If error is larger than 50000, make sure the user-defined message is added using sp_addmessage.
Sign up to request clarification or add additional context in comments.

1 Comment

I agree, error code 18054 maps to the error "no message with that error number was found in sys.messages"
0

There is one small caveat: You can't supply a message on your own in this case. But this can be circumvented by adding an additional %s in the sp_addmessage call or by changing all mapped messages to your own pattern and supplying the right parameters in the raiseerror call.

Check there for more information: SQL Server: Rethrow exception with the original exception number

RAISERROR can either reference a user-defined message stored in the sys.messages catalog view or build a message dynamically.

Check for your error message exists or not using this:

select * from sys.messages

If it does not exists then Use sp_addmessage to add user-defined error messages and sp_dropmessage to delete user-defined error messages.

for more information follow RaiseError documentation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.