OnError Event

DTS Programming

DTS Programming

OnError Event

The OnError event indicates and provides information about an error. It allows the event handler to cancel task execution.

Applies To
Package Object Package2 Object
Syntax (Visual Basic)

Sub objPackage_OnError(ByVal EventSource As String, ByVal ErrorCode As Long, _
    ByVal Source As String, ByVal Description As String, ByVal HelpFile As String, _
    ByVal HelpContext As Long, ByVal IDOfInterfaceWithError As String, _
    ByVal pbCancel As Boolean)

Part Description
objPackage Object variable of a type specified in the Applies To list.
EventSource Source of event being executed (for example, a step name).
ErrorCode Error code of the failure.
Source Source of error message (for example, an OLE DB provider description).
Description Description of the error.
HelpFile Help file name.
HelpContext Help context ID.
IDOfInterfaceWithError ID of the user interface returning the error, a globally unique identifier (GUID).
pbCancel Boolean that specifies whether to cancel task execution.

Remarks

The OnError event occurs during the Package2 object Execute method. An error can be raised by a Data Transformation Services (DTS) component or by a custom task. When an error occurs in execution, the OnError event is raised before return from the Execute method.

Use the pbCancel argument to direct package execution on error. When the OnError handler sets Cancel to TRUE, execution of the package is terminated on return from the error handler. When Cancel is FALSE, DTS package execution continues.

The OnError event is raised on each error occurring in a task or step. A step does not necessarily terminate after an error. For example, the MaximumErrorCount property of the DataPumpTask2 object specifies the number of errors that can occur before the task is terminated.

For task types defined by DTS, the EventSource argument specifies a step name. Custom tasks choose what to return for EventSource. When an error is not caused by or associated with a step, the EventSource argument is empty.

If you need to raise this event from a custom task implemented in Microsoft® Visual Basic®, use this syntax:

pPackageEvents.OnError EventSource, ErrorCode, Source, Description, _
    HelpFile, HelpContext, IDOfInterfaceWithError, pbCancel

pPackageEvents is a reference to the package events object, passed in as a parameter of the custom task Execute method that you have implemented. When the event returns, terminate task execution if pbCancel is TRUE.

Prototype (C/C++)

HRESULT OnError(
    BSTR EventSource,
    long ErrorCode,
    BSTR Source,
    BSTR Description,
    BSTR HelpFile,
    long HelpContext,
    BSTR IDOfInterfaceWithError,
    BOOL *pbCancel);

See Also

Execute Method

Handling DTS Events and Errors