sp_OAGetErrorInfo

Obtains OLE Automation error information.

Syntax

sp_OAGetErrorInfo [objecttoken [, source OUTPUT [, description OUTPUT
[, helpfile OUTPUT [, helpid OUTPUT ]]]]]

where

objecttoken
Is the object token of an OLE object previously created by sp_OACreate or NULL. If an object token is specified, error information for that object will be returned. If NULL is specified, the error information for the entire batch will be returned.
source OUTPUT
Is the source of the error information. If specified, it must be a local char or varchar variable. The return value will be truncated to fit the local variable if necessary.
description OUTPUT
Is the description of the error. If specified, it must be a local char or varchar variable. The return value will be truncated to fit the local variable if necessary.
helpfile OUTPUT
Is the Help file for the OLE object. If specified, it must be a local char or varchar variable. The return value will be truncated to fit the local variable if necessary.
helpid OUTPUT
Is the Help file context ID. If specified, it must be a local int variable.

Remarks

Each call to an OLE Automation stored procedure (except sp_OAGetErrorInfo) resets the error information, so sp_OAGetErrorInfo obtains error information only for the most recent OLE Automation stored procedure call. Note that because sp_OAGetErrorInfo does not reset the error information, it can be called multiple times to get the same error information.

If no output parameters are specified, the error information is returned to the client as a results set.

This procedure returns a 0 when successful or a non-zero HRESULT when an error occurs.

This table is a list of OLE Automation errors and their common causes.


Error and HRESULT Common cause

Bad variable type
(0x80020008)
The datatype of a Transact-SQL value passed as a method parameter did not match the Visual Basic data type of the method parameter, or a NULL value was passed as a method parameter.

Ensure that any local variables used as method parameters are of the appropriate datatype and are set to a value other than NULL.

Unknown name
(0x8002006)
The specified property or method name was not found for the specified object.
Invalid class string
(0x800401f3)
The specified ProgID or CLSID is not been registered as an OLE object on the SQL Server computer.
Server execution failed
(0x80080005)
The specified OLE object is registered as a local OLE server (.EXE file) but the .EXE file could not be found or started.
The specified module could not be found
(0x8007007e)
The specified OLE object is registered as an in-process OLE server (.DLL file), but the .DLL file could not be found or loaded.
Type mismatch
(0x80020005)
The datatype of a Transact-SQL local variable used to store a returned property value or a method return value did not match the Visual Basic data type of the property or method return value.

Ensure that the local variable is of the appropriate datatype.

Or, the return value of a property or a method was requested, but it does not return a value.

Parameter not found
(0x80020004)
A named parameter was specified before a positional parameter.

Ensure that all named parameters are specified after all positional parameters.

The parameter is incorrect
(0x80070057)
The number specified as the context parameter of sp_OACreate was not valid.

Example

This example displays OLE Automation error information.

DECLARE @output varchar(255)
DECLARE @hr int
DECLARE @source varchar(255)
DECLARE @description varchar(255)
PRINT 'OLE Automation Error Information'
EXEC @hr = sp_OAGetErrorInfo @object, @source OUT, @description OUT
IF @hr = 0
BEGIN
    SELECT @output = '  Source: ' + @source
    PRINT @output
    SELECT @output = '  Description: ' + @description
    PRINT @output
END
ELSE
BEGIN
    PRINT '  sp_OAGetErrorInfo failed.'
    RETURN
END