Article ID: 145643 - Last Review: November 14, 2003 - Revision: 3.0 INF: Processing DBCC Commands in ODBC applicationsThis article was previously published under Q145643 SUMMARY
This article discusses how the ODBC applications that use the Microsoft SQL
Server ODBC Driver can process the output of DBCC commands. SQL Server
drivers from other vendors may return DBCC information differently, and you
should refer to the documentation for those drivers.
MORE INFORMATION
Microsoft SQL Server applications can use the Transact-SQL DBCC commands to
get additional information from the server, such as information on the
choices made by the server's optimizer, locking information, table
consistency, and so forth.
All the information returned to applications from DBCC commands does not come back in a result set. In DB-library applications, the output comes back to the application's message handler. The Microsoft SQL Server ODBC driver returns the output by returning SQL_SUCCESS_WITH_INFO on the ODBC function that executes the command. The application can then retrieve the DBCC output by calling the SQLError() function. There are two main classes of DBCC commands with regard to the time at which the application should expect SQL_SUCCESS_WITH_INFO and call SQLError(). The first class is the DBCC output generated through the DBCC TRACEON trace flags. Some of the DBCC trace flags generate trace information whenever the server processes an SQL command. For example, the 4032 flag traces each SQL command as it is received at the server, and the 310 flag shows information about the join order used. The output destination of the trace flags is controlled with the 3605/3604 trace flags. If the 3604 flag is turned on, then trace flag output is returned to the application; if the 3605 flag is on, then trace output is sent to the SQL Server errorlog. When an ODBC application sets the 3604 flag in conjunction with a trace flag that generates (like 4032 or 310), then SQLExecute or SQLExecDirect for each SQL command will return SQL_SUCCESS_WITH_INFO. When the application then calls SQLError(), each call to SQLError() will return a line of the trace output. Many of the flags will return multiple lines of output, so the application should call SQLError() until it returns SQL_NO_DATA_FOUND. For example, if an ODBC application does: The second SQLExecDirect will return SQL_SUCCESS_WITH_INFO, and a call to SQLError() will then return one line of trace output: All of the other DBCC commands fall into the second class regarding the way they return output. All of the other DBCC commands return SQL_SUCCESS_WITH_INFO when the DBCC command is executed, and the application can retrieve the output by calling SQLError() until it returns SQL_NO_DATA_FOUND. For example, if an ODBC application does: This SQLExecDirect will return SQL_SUCCESS_WITH_INFO and calls to SQLError() will return the following lines: APPLIES TO
| Article Translations
|


Back to the top
