Skip to content

Latest commit

 

History

History
64 lines (54 loc) · 5.69 KB

understanding-database-engine-errors.md

File metadata and controls

64 lines (54 loc) · 5.69 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic helpviewer_keywords monikerRange
Understanding Database Engine Errors
Learn about the attributes of errors raised by the SQL Server Database Engine and how to access all system and user-defined error messages from sys.messages.
MashaMSFT
mathoma
03/16/2017
sql
supportability
concept-article
errors [SQL Server], about errors
errors [SQL Server], Database Engine
errors [SQL Server]
Database Engine [SQL Server], errors
>=aps-pdw-2016||=azuresqldb-current||=azure-sqldw-latest||>=sql-server-2016||>=sql-server-linux-2017||=azuresqldb-mi-current||=fabric

Understanding Database Engine Errors

[!INCLUDESQL Server Azure SQL Database Synapse Analytics PDW FabricSE FabricDW] Errors raised by the [!INCLUDEmsCoName] [!INCLUDEssDEnoversion] have the attributes described in the following table.

Attribute Description
Error number Each error message has a unique error number.
Error message string The error message contains diagnostic information about the cause of the error. Many error messages have substitution variables in which information, such as the name of the object generating the error, is inserted.
Severity The severity indicates how serious the error is. Errors that have a low severity, such as 1 or 2, are information messages or low-level warnings. Errors that have a high severity indicate problems that should be addressed as soon as possible. For more information about severities, see Database Engine Error Severities.
State Some error messages can be raised at multiple points in the code for the [!INCLUDEssDE]. For example, an 1105 error can be raised for several different conditions. Each specific condition that raises an error assigns a unique state code.

When you are viewing databases that contain information about known issues, such as the [!INCLUDEmsCoName] Knowledge Base, you can use the state number to determine whether the recorded issue is the same as the error you have encountered. For example, if a Knowledge Base Article describes an 1105 error that has a state of 2 and the 1105 error message you received had a state of 3, the error probably has a different cause than the one reported in the article.

A [!INCLUDEmsCoName] support engineer can also use the state code from an error to find the location in the source code where that error code is being raised. This information might provide additional ideas on how to diagnose the problem.
Procedure name Is the name of the stored procedure or trigger in which the error has occurred.
Line number Indicates which statement in a batch, stored procedure, trigger, or function generated the error.

All system and user-defined error messages in an instance of the [!INCLUDEssDE] are contained in the sys.messages catalog view. You can use the RAISERROR statement to return user-defined errors to an application.

All database APIs, such as the [!INCLUDEmsCoName] [!INCLUDEdnprdnshort] SQLClient namespace, ActiveX Data Objects (ADO), OLE DB, and Open Database Connectivity (ODBC), report the basic error attributes. This information includes the error number and message string. However, not all the APIs report all the other error attributes.

Information about an error that occurs in the scope of the TRY block of a TRY...CATCH construct can be obtained in [!INCLUDEtsql] code by using functions such as ERROR_LINE, ERROR_MESSAGE, ERROR_NUMBER, ERROR_PROCEDURE, ERROR_SEVERITY, and ERROR_STATE in the scope of the associated CATCH block. For more information, see TRY...CATCH (Transact-SQL).

Examples

The following example queries the sys.messages catalog view to return a list of all system and user-defined error messages in the [!INCLUDEssDE] that have English text (1033).

SELECT  
    message_id,  
    language_id,  
    severity,  
    is_event_logged,  
    text  
  FROM sys.messages  
  WHERE language_id = 1033;  

For more information, see sys.messages (Transact-SQL).

See Also

sys.messages (Transact-SQL)
RAISERROR (Transact-SQL)
@@ERROR (Transact-SQL)
TRY...CATCH (Transact-SQL)
ERROR_LINE (Transact-SQL)
ERROR_MESSAGE (Transact-SQL)
ERROR_NUMBER (Transact-SQL)
ERROR_PROCEDURE (Transact-SQL)
ERROR_SEVERITY (Transact-SQL)
ERROR_STATE (Transact-SQL)