ODBC Error Message Format

Troubleshooting SQL Server

Troubleshooting

ODBC Error Message Format

ODBC drivers return messages to applications as diagnostic records. An application can call the SQLGetDiagRec and SQLGetDiagField functions to retrieve these diagnostic records. The Microsoft® SQL Server™ ODBC driver maps SQL Server message parts into these standard ODBC diagnostic record fields:

SQLSTATE

The ODBC specification defines a set of five-character codes called SQLSTATE codes that identify the conditions generating the message. These SQLSTATE codes are not related to any of the parts of a SQL Server message. The SQL Server ODBC driver generates the appropriate SQLSTATE code anytime it returns a message to an application.

pfNative

The SQL Server ODBC driver returns the SQL Server error number as the ODBC pfNative field. For example, if a statement raises a SQL Server error 170 (syntax error), the ODBC driver returns 170 in pfNative.

MessageText

The SQL Server ODBC driver returns the SQL Server error description as the MessageText field in an ODBC diagnostic record. The ODBC specification defines a series of headers for the MessageText field that indicates the component that issued the message:

  • [Microsoft][ODBC Driver Manager]

    These messages are issued by the ODBC Driver Manager.

  • [Microsoft][ODBC Cursor Library]

    These messages are issued by the ODBC client cursor library.

  • [Microsoft][ODBC SQL Server Driver]

    These messages are issued by the SQL Server ODBC driver. If there are no other nodes with the name of either a Net-Library or a SQL Server installation, the message was issued by the driver.

  • [Microsoft][ODBC SQL Server Driver][Net-Libraryname]

    These messages are issued by the SQL Server Net-Library, where Net-Libraryname is the display name of a SQL Server client Net-Library (for example, Named Pipes, Shared Memory, Multiprotocol, TCP/IP Sockets, NWLink IPX/SPX, or Banyan VINES).

  • [Microsoft][ODBC SQL Server Driver][SQL Server]

    These messages are issued by SQL Server. The remainder of the error message is the description from SQL Server, usually from master.dbo.sysmessages.

The ODBC specification allows ODBC drivers to define driver-specific fields in ODBC diagnostic records. The SQL Server ODBC driver maps SQL Server message parts into these SQL Server ODBC driver-specific diagnostic fields:

SQL_DIAG_SS_SEVERITY.

Contains the SQL Server severity level.

SQL_DIAG_SS_MSGSTATE.

Contains the SQL Server state. It is not related to the ODBC SQLSTATE code.

SQL_DIAG_SS_LINE.

Contains the number of the line containing the SQL statement generating the message.

SQL_DIAG_SS_PROCNAME.

Contains the name of the stored procedure generating the message, if appropriate.

SQL_DIAG_SS_SRVNAME.

Contains the name of the server from which the message came.

See Also

Handling Errors and Messages