Writing Log Data from a DTS Custom Task

DTS Programming

DTS Programming

Writing Log Data from a DTS Custom Task

Custom tasks can write log records to the Microsoft® SQL Server™ task log table and to the Data Transformation Services (DTS) package log file.

You write log records through a reference to a PackageLog object, which is one of the parameters of CustomTask_Execute. Check the reference for NULL or Nothing before using it.

Example

The following Microsoft Visual Basic® code writes a log file record specifying the number of rows processed upon successful completion. If an error occurs within CustomTask_Execute, a task log record is written. Then the error is propagated back to the caller:

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

On Error GoTo ErrorHandler

. . .

'Write rows processed message to log, if log object valid.
If Not pPackageLog Is Nothing Then
    pPackageLog.WriteStringToLog _
        Me.Description & ": Rows processed = " & (lngRowCount)
End If
pTaskResult = DTSTaskExecResult_Success
Exit Sub

ErrorHandler:
Dim lngErrorCode   As Long
'Write error information to task log, if log object valid.
If Not pPackageLog Is Nothing Then
    pPackageLog.WriteTaskRecord Err.Number, _
                Me.Description & ": " & Err.Description
End If
pTaskResult = DTSTaskExecResult_Failure

'Extend error code to 32 bits if necessary, then propagate error.
lngErrorCode = Err.Number
If lngErrorCode >= 0 And lngErrorCode < 65536 Then
    lngErrorCode = lngErrorCode + vbObjectError
End If
Err.Raise lngErrorCode, Me.Description & "/" & Err.Source, Err.Description
End Sub

Log file strings are written only if the package LogFileName property has been set to the log file specification. Log file strings and task log records also can be written through the DTSPackageLog scripting object from scripts within the ActiveScriptTask object.

See Also

ActiveScriptTask Object

LogFileName Property

PackageLog Object