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 following methods exposed by the Events property:
Event | Description |
---|---|
Raises a user-defined custom event in the package. |
|
Informs the package of an error condition. |
|
Provides information to the user. |
|
Informs the package of the progress of the task. |
|
Returns a value that indicates whether the package needs the task to shut down prematurely. |
|
Informs the package that the task is in a state that warrants user notification, but is not an error condition. |
Events Example
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 = Dts.Results.Success
End Sub
See Also
Other Resources
Integration Services Event Handlers
Creating Package Event Handlers
Help and Information
Getting SQL Server 2005 Assistance
Change History
Release | History |
---|---|
14 April 2006 |
|