SQLGetDiagField

 

System_CAPS_ICON_warning.jpg Warning

SQL Server Native Client (SNAC) is not supported beyond SQL Server 2012. Avoid using SNAC in new development work, and plan to modify applications that currently use it. The Microsoft ODBC Driver for SQL Server provides native connectivity from Windows to Microsoft SQL Server and Microsoft Azure SQL Database.

The SQL Server Native Client ODBC driver specifies the following additional diagnostics fields for SQLGetDiagField. These fields support rich error reporting for SQL Server applications and are available in all diagnostics records generated on connected ODBC connection handles and ODBC statement handles. The fields are defined in sqlncli.h.

Diagnostics record fieldDescription
SQL_DIAG_SS_LINEReports the line number of a stored procedure generating an error. The value of SQL_DIAG_SS_LINE is meaningful only if SQL_DIAG_SS_PROCNAME returns a value. The value is returned as an unsigned, 16-bit integer.
SQL_DIAG_SS_MSGSTATEThe state of an error message. For information about the error message state, see RAISERROR. The value is returned as a signed, 32-bit integer.
SQL_DIAG_SS_PROCNAMEName of the stored procedure generating an error, if appropriate. The value is returned as a character string. The length of the string (in characters) depends on the version of the SQL Server. It can be determined by calling SQLGetInfo requesting the value for SQL_MAX_PROCEDURE_NAME_LEN.
SQL_DIAG_SS_SEVERITYThe severity level of the associated error message. The value is returned as a signed, 32-bit integer.
SQL_DIAG_SS_SRVNAMEThe name of the server on which the error occurred. The value is returned as a character string. The length of the string (in characters) is defined by the SQL_MAX_SQLSERVERNAME macro in sqlncli.h.

SQL Server-specific diagnostic fields that contain character data, SQL_DIAG_SS_PROCNAME and SQL_DIAG_SS_SRVNAME, return that data to the client as null terminated, ANSI, or Unicode strings. If necessary, the count of characters should be adjusted by the character width. Alternately, a portable C data type such as TCHAR or SQLTCHAR can be used to ensure correct program variable length.

The SQL Server Native Client ODBC driver reports the following additional dynamic function codes that identify the last attempted SQL Server statement. The dynamic function code is returned in the header (record 0) of the diagnostics record set and is therefore available on every execution (successful or not).

Dynamic function codeSource
SQL_DIAG_DFC_SS_ALTER_DATABASEALTER DATABASE statement
SQL_DIAG_DFC_SS_CHECKPOINTCHECKPOINT statement
SQL_DIAG_DFC_SS_CONDITIONError arose in the WHERE or HAVING clauses of a statement.
SQL_DIAG_DFC_SS_CREATE_DATABASECREATE DATABASE statement
SQL_DIAG_DFC_SS_CREATE_DEFAULTCREATE DEFAULT statement
SQL_DIAG_DFC_SS_CREATE_PROCEDURECREATE PROCEDURE statement
SQL_DIAG_DFC_SS_CREATE_RULECREATE RULE statement
SQL_DIAG_DFC_SS_CREATE_TRIGGERCREATE TRIGGER statement
SQL_DIAG_DFC_SS_CURSOR_DECLAREDECLARE CURSOR statement
SQL_DIAG_DFC_SS_CURSOR_OPENOPEN statement
SQL_DIAG_DFC_SS_CURSOR_FETCHFETCH statement
SQL_DIAG_DFC_SS_CURSOR_CLOSECLOSE statement
SQL_DIAG_DFC_SS_DEALLOCATE_CURSORDEALLOCATE statement
SQL_DIAG_DFC_SS_DBCCDBCC statement
SQL_DIAG_DFC_SS_DENYDENY statement
SQL_DIAG_DFC_SS_DROP_DATABASEDROP DATABASE statement
SQL_DIAG_DFC_SS_DROP_DEFAULTDROP DEFAULT statement
SQL_DIAG_DFC_SS_DROP_PROCEDUREDROP PROCEDURE statement
SQL_DIAG_DFC_SS_DROP_RULEDROP RULE statement
SQL_DIAG_DFC_SS_DROP_TRIGGERDROP TRIGGER statement
SQL_DIAG_DFC_SS_DUMP_DATABASEBACKUP or DUMP DATABASE statement
SQL_DIAG_DFC_SS_DUMP_TABLEDUMP TABLE statement
SQL_DIAG_DFC_SS_DUMP_TRANSACTIONBACKUP or DUMP TRANSACTION statement. Also returned for a CHECKPOINT statement if the trunc. log on chkpt. database option is on.
SQL_DIAG_DFC_SS_GOTOGOTO control-of-flow statement
SQL_DIAG_DFC_SS_INSERT_BULKINSERT BULK statement
SQL_DIAG_DFC_SS_KILLKILL statement
SQL_DIAG_DFC_SS_LOAD_DATABASELOAD or RESTORE DATABASE statement
SQL_DIAG_DFC_SS_LOAD_HEADERONLYLOAD or RESTORE HEADERONLY statement
SQL_DIAG_DFC_SS_LOAD_TABLELOAD TABLE statement
SQL_DIAG_DFC_SS_LOAD_TRANSACTIONLOAD or RESTORE TRANSACTION statement
SQL_DIAG_DFC_SS_PRINTPRINT statement
SQL_DIAG_DFC_SS_RAISERRORRAISERROR statement
SQL_DIAG_DFC_SS_READTEXTREADTEXT statement
SQL_DIAG_DFC_SS_RECONFIGURERECONFIGURE statement
SQL_DIAG_DFC_SS_RETURNRETURN control-of-flow statement
SQL_DIAG_DFC_SS_SELECT_INTOSELECT INTO statement
SQL_DIAG_DFC_SS_SETSET statement (generic, all options)
SQL_DIAG_DFC_SS_SET_IDENTITY_INSERTSET IDENTITY_INSERT statement
SQL_DIAG_DFC_SS_SET_ROW_COUNTSET ROWCOUNT statement
SQL_DIAG_DFC_SS_SET_STATISTICSSET STATISTICS IO or SET STATISTICS TIME statements
SQL_DIAG_DFC_SS_SET_TEXTSIZESET TEXTSIZE statement
SQL_DIAG_DFC_SS_SETUSERSETUSER statement
SQL_DIAG_DFC_SS_SET_XCTLVLSET TRANSACTION ISOLATION LEVEL statement
SQL_DIAG_DFC_SS_SHUTDOWNSHUTDOWN statement
SQL_DIAG_DFC_SS_TRANS_BEGINBEGIN TRAN statement
SQL_DIAG_DFC_SS_TRANS_COMMITCOMMIT TRAN statement
SQL_DIAG_DFC_SS_TRANS_PREPAREPrepare to commit a distributed transaction
SQL_DIAG_DFC_SS_TRANS_ROLLBACKROLLBACK TRAN statement
SQL_DIAG_DFC_SS_TRANS_SAVESAVE TRAN statement
SQL_DIAG_DFC_SS_TRUNCATE_TABLETRUNCATE TABLE statement
SQL_DIAG_DFC_SS_UPDATE_STATISTICSUPDATE STATISTICS statement
SQL_DIAG_DFC_SS_UPDATETEXTUPDATETEXT statement
SQL_DIAG_DFC_SS_USEUSE statement
SQL_DIAG_DFC_SS_WAITFORWAITFOR control-of-flow statement
SQL_DIAG_DFC_SS_WRITETEXTWRITETEXT statement

SQLGetDiagField can be used to retrieve two diagnostic fields: SQL_DIAG_SS_TABLE_COLUMN_NUMBER and SQL_DIAG_SS_TABLE_ROW_NUMBER. These fields help you determine which value caused the error or warning associated with the diagnostic record.

For more information about table-valued parameters, see Table-Valued Parameters (ODBC).

SQLGetDiagField Function
ODBC API Implementation Details

Community Additions

ADD
Show: