Posts

Showing posts with the label Error Handling

Define function available in catch block of SQL

Below are the different functions use inside CATCH block:- (1)ERROR_NUMBER:- The number of the error that occurred. This is similar to @@ERROR except that it will return the same number for the duration of the CATCH block. (2)ERROR_MESSAGE:- The complete text of the error message including any substitute parameters such as object names. (3)ERROR_LINE:- This is the line number of the batch or stored procedure where the error occurred. (4)ERROR_SEVERITY:- This is the severity of the error. The CATCH block only fires for errors with severity 11 or higher. Error severity from 11 to 16 are typically user or code errors. Severity levels from 17 to 25 are usually software or hardware errors where processing may not be able to continue. (5)ERROR_STATE:- This is sometimes used by the system to return more information about the error. (6)ERROR_PROCEDURE:- If the error was generated inside a stored procedure this will hold the name of the proce...

The Anatomy of an Error Message

Here is a typical error message you can get from SQL Server when working from Query Analyzer. Server: Msg 547, Level 16, State 1, Procedure error_demo_sp, Line 2 UPDATE statement conflicted with COLUMN FOREIGN KEY constraint 'fk7_acc_cur'. The conflict occurred in database 'bos_sommar', table 'currencies', column 'curcode'. The statement has been terminated. Note: Under Tools -> Options -> Connections, I have checked Parse ODBC Message Prefixes . The error information that SQL Server passes to the client consists of several components, and the client is responsible for the final interpretation of the message. These are the components that SQL Server passes to the client. Message number – each error message has a number. You can find most of the message numbers in the table sysmessages in the master database. (There some special numbers like 0 and 50000 that do not appear there.) In this example, the message number i...