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.




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.

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.

using System;
using System.Data;
using Microsoft.SqlServer.Dts.Runtime;
using System.Windows.Forms;
using System.Runtime.InteropServices;

public class ScriptMain

        private extern static long InternetGetConnectedState(ref long dwFlags, long dwReserved);

        private enum ConnectedStates
            LAN = 0x2,
            Modem = 0x1,
            Proxy = 0x4,
            Offline = 0x20,
            Configured = 0x40,
            RasInstalled = 0x10

        public void Main()
            long dwFlags = 0;
            long connectedState;
            bool fireAgain = true;
            int state;

            connectedState = InternetGetConnectedState(ref dwFlags, 0);
            state = (int)ConnectedStates.Modem;
            if (connectedState != 0)
                if ((dwFlags & state) == state)
                    Dts.Events.FireWarning(0, "Script Task Example", "Volatile Internet connection detected.", String.Empty, 0);
                    Dts.Events.FireInformation(0, "Script Task Example", "Internet connection detected.", String.Empty, 0, ref fireAgain);
                // If not connected to the Internet, raise an error.
                Dts.Events.FireError(0, "Script Task Example", "Internet connection not available.", String.Empty, 0);

            Dts.TaskResult = (int)ScriptResults.Success;


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