Using sp_DisplayOAErrorInfo

SQL Server's sp_OAGetErrorInfo stored procedure provides all the information you need to pass up to your application's middle and client tiers when an error occurs.

James T. Stanley

August 11, 2000

1 Min Read
ITPro Today logo in a gray background | ITPro Today

SQL Server's sp_OAGetErrorInfo stored procedure provides all the information you need to pass up to your application's middle and client tiers when an error occurs. However, writing an error handler to pass this error information can be time-consuming. In addition, if you don't interactively run the procedure that automates the COM object but instead schedule the procedure with the SQL Agent (SQL Executive in SQL Server 6.5), you'll want to log the information somehow.

Fortunately, SQL Server Books Online (BOL) includes a sample stored procedure called sp_DisplayOAErrorInfo. This procedure calls sp_OAGetErrorInfo for you and combines the returned values into formatted strings. The procedure then passes these strings to a T-SQL print statement, which outputs them either as messages to an ADO or RDO client when you run the procedure interactively or as entries in the SQL Agent log when you schedule the procedure.

To use sp_DisplayOAErrorInfo, place the following code after a call to any of the automation procedures. (This example assumes that @Object holds the object's object token and that @hr holds the return value from the automation call.)

If @hr <> 0BEGINExec sp_DisplayOAErrorInfo @Object, @hrReturnEND

To find stored procedure sp_DisplayOAErrorInfo's sample source code, look in BOL under the heading "sp_OAGetErrorInfo" for SQL Server 7.0 or "HRESULT Return Codes" for SQL Server 6.5.

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like