Export (0) Print
Expand All

Raising Events from a DTS Custom Task

SQL Server 2000

Raising Events from a DTS Custom Task

A custom task raises package events that are handled by the parent application. Typically, it raises the following events.

Event Purpose Frequency
OnError To notify the parent application that an error has occurred, especially non-fatal errors. When an error occurs.
OnProgress To notify the parent application of progress in task processing. Every time a few units (for example, rows) process, or every few seconds.
OnQueryCancel To give the parent application the opportunity to terminate the custom task. In Data Transformation Services (DTS) Designer, click Cancel to handle this event. Every few seconds.

Note  In DTS, you do not need to raise OnStart or OnFinish because each DTS step raises OnStart when it starts and OnFinish when it finishes.

OnQueryCancel and OnError have a pbCancel parameter. If the handling application sets pbCancel, the custom task should terminate execution by returning from the CustomTask_Execute method.

One of the parameters of CustomTask_Execute is a reference through which package events can be raised. Check for NULL or Nothing (depending on programming language) before using it.

Example

The following Microsoft® Visual Basic® code raises OnProgress and OnQueryCancel and then terminates the task if requested:

Private Sub CustomTask_Execute(ByVal pPackage As Object, _
            ByVal pPackageEvents As Object, ByVal pPackageLog As Object, _
            pTaskResult As DTS.DTSTaskExecResult)
Dim lngRowCount     As Long
Dim blnCancel       As Boolean

. . .

'Make sure package events object is valid.
If Not pPackageEvents Is Nothing Then

    'Raise OnProgress and OnQueryCancel, and then exit if response says to cancel.
    pPackageEvents.OnProgress Me.Description, "Row Count", _
            0, lngRowCount, 0
    pPackageEvents.OnQueryCancel Me.Description, blnCancel
    If blnCancel Then 
        pTaskResult = DTSTaskExecResult_Failure
        Exit Sub
    End If
End If

. . .

pTaskResult = DTSTaskExecResult_Success
End Sub
Show:
© 2014 Microsoft