Error Handling

Accessing and Changing Relational Data

Accessing and Changing Relational Data

Error Handling

Errors raised in Microsoft® SQL Server™ 2000 have several attributes:

  • Error number.

    Each error condition has a unique error number.

  • Error message string.

    The error message gives 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 placed. Every error number has a unique error message.

  • Severity.

    The severity indicates how serious the error is. Errors with a low severity, such as 1 or 2, are information messages or low-level warnings. Errors with a high severity indicate problems that should be addressed as soon as possible.

  • State code.

    Some error codes can be raised at multiple points in the source code for SQL Server. For example, an "1105" error can be raised for several different conditions. Each place the error code is raised assigns a unique state code. A Microsoft support engineer can use the state code from an error to find the location in the source code where that error code is being raised, which may provide additional ideas on how to diagnose the problem.

  • Procedure name.

    If the error occurred in a stored procedure, the name of the stored procedure may be available.

  • Line number.

    The line number indicates which statement in a stored procedure generated the error.

All of the SQL Server errors are stored in the system table master.dbo.sysmessages. User-defined messages can also be stored in sysmessages. The RAISERROR statement can then be used to return these user-defined errors to an application if necessary.

All the database APIs, such as ADO, OLE DB, ODBC, DB-Library, and Embedded SQL, report the basic error attributes: the error number and message string. However, there are variations in how many of the other error attributes each database can report.

Other SQL Server components can also raise errors:

  • The OLE DB provider, ODBC driver, and DB-Library dynamic-link library raise errors of their own. The format of these errors is consistent with the formats defined in the API specifications.

  • The Net-Libraries raise errors of their own.

  • Open Data Services raises errors in its own format.

  • The SQL Server wizards, applications, and utilities such as the Index Tuning Wizard, SQL Server Enterprise Manager, and the osql utility can raise their own errors.

  • Embedded SQL can raise SQL-92 errors.

See Also