How to set SQLException Number


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?


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.


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: <a href="https://stackoverflow.com/questions/1882788/sql-server-rethrow-exception-with-the-original-exception-number" rel="nofollow">SQL Server: Rethrow exception with the original exception number</a>


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 <a href="http://msdn.microsoft.com/en-us/library/ms178592.aspx" rel="nofollow">RaiseError</a> documentation.


  • How to edit css for jquery datepicker prev/next buttons?
  • Spring Web Flow exception handling
  • Angular Ui-router can't access $stateParams inside my controller
  • Subversion reverting resolved file
  • QPushButton is not changing the background-color proper
  • How to synchronize two scrollview in Android?
  • How do I check if System::Collections:ArrayList is empty / nullptr / null?
  • Creating a C++ function that calls other Lua function
  • INSERT EXEC Statement cannot be nested [duplicate]
  • Losing my session variables
  • Responsive left sidebar open close
  • How to get the date of next specified day of week
  • Python cosine function precision [duplicate]
  • converter json to two dimensional array
  • How Get arguments value using inline assembly in C without Glibc?
  • How to make R's read_csv2() recognise the text characters properly
  • Implementation of State Monad
  • Why Encoding.ASCII != ASCIIEncoding.Default in C#?
  • How to define and use opencv mat of user type
  • one Local Olampyad Questions on Informatic in 2011
  • How do I pass the string value parameter of the selected list item from an auto-populated dropdown l
  • Linq Objects Group By & Sum
  • jQuery show() function is not executed in Safari if submit handler returns true
  • Optimizing database types to compact database (SQLite)
  • Cassandra Data Model
  • Deserializing XML into class C#
  • When should I choose bucket sort over other sorting algorithms?
  • Function pointer “assignment from incompatible pointer type” only when using vararg ellipsis
  • 0x202A in filename: Why?
  • Buffer size for converting unsigned long to string
  • KeystoneJS: Relationships in Admin UI not updating
  • Getting Messege Twice Using IMvxMessenger
  • Turn off referential integrity in Derby? is it possible?
  • Authorize attributes not working in MVC 4
  • python draw pie shapes with colour filled
  • Busy indicator not showing up in wpf window [duplicate]
  • reshape alternating columns in less time and using less memory
  • How to Embed XSL into XML
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF