Export (0) Print
Expand All

Raising Events in the Script Task

Events provide a way to report errors, warnings, and other information, such as task progress or status, to the containing package. The package provides event handlers for managing event notifications. The Script task can raise events by calling methods on the Events property of the Dts object. For more information about how Integration Services packages handle events, see Integration Services Event Handlers.

Events can be logged to any log provider that is enabled in the package. Log providers store information about events in a data store. The Script task can also use the Log method to log information to a log provider without raising an event. For more information about how to use the Log method, see Logging in the Script Task.

To raise an event, the Script task calls one of the methods exposed by the Events property. The following table lists the methods exposed by the Events property.

Event

Description

FireCustomEvent

Raises a user-defined custom event in the package.

FireError

Informs the package of an error condition.

FireInformation

Provides information to the user.

FireProgress

Informs the package of the progress of the task.

FireQueryCancel

Returns a value that indicates whether the package needs the task to shut down prematurely.

FireWarning

Informs the package that the task is in a state that warrants user notification, but is not an error condition.

The following example demonstrates how to raise events from within the Script task. The example uses a native Windows API function to determine whether an Internet connection is available. If no connection is available, it raises an error. If a potentially volatile modem connection is in use, the example raises a warning. Otherwise, it returns an informational message that an Internet connection has been detected.

Private Declare Function InternetGetConnectedState Lib "wininet" _
    (ByRef dwFlags As Long, ByVal dwReserved As Long) As Long

Private Enum ConnectedStates
    LAN = &H2
    Modem = &H1
    Proxy = &H4
    Offline = &H20
    Configured = &H40
    RasInstalled = &H10
End Enum

Public Sub Main()

    Dim dwFlags As Long
    Dim connectedState As Long
    Dim fireAgain as Boolean

    connectedState = InternetGetConnectedState(dwFlags, 0)

    If connectedState <> 0 Then
        If (dwFlags And ConnectedStates.Modem) = ConnectedStates.Modem Then
            Dts.Events.FireWarning(0, "Script Task Example", _
                "Volatile Internet connection detected.", String.Empty, 0)
        Else
            Dts.Events.FireInformation(0, "Script Task Example", _
                "Internet connection detected.", String.Empty, 0, fireAgain)
        End If
    Else
        ' If not connected to the Internet, raise an error.
        Dts.Events.FireError(0, "Script Task Example", _
            "Internet connection not available.", String.Empty, 0)
    End If

    Dts.TaskResult = ScriptResults.Success

End Sub
Integration Services icon (small) Stay Up to Date with Integration Services

For the latest downloads, articles, samples, and videos from Microsoft, as well as selected solutions from the community, visit the Integration Services page on MSDN or TechNet:

For automatic notification of these updates, subscribe to the RSS feeds available on the page.

Community Additions

ADD
Show:
© 2014 Microsoft