2.4. Raising Error Events

Sometimes the logic in your Script Task can be quite complex, and you may want to raise an error intentionally without causing the entire task to fail. For example, if you try to encrypt a file and the file name doesn't match what you expect even though your Visual Basic .NET syntax is fine, you may want to raise an error.

You can force the entire task to fail by using the Dts.Results.Failure method, but the error that is logged is not verbose to diagnose why the failure occurred. SSIS would only report a general failure.

In the Microsoft.SqlServer.Dts.Runtime namespace's interface, IDTSComponentEvents contains events that can be wired within the Script Task. When an error occurs, the FireError method can be used to raise the error. The parameters shown in the following table are passed to expose information about the error that occurred.

PARAMETERDATA TYPEDESCRIPTION
errorCodeIntegerUnique identifier of the error message
subComponentStringSpecific information as to where the event originated
DescriptionStringExplanation about why the error occurred
helpFileStringLocation of the file that gives specific information about the error
helpContextIntegerUnique identification of the information source within the Help file

The following example shows how to throw an error through code:

Dts.Events.FireError(1234, "", "Here is an error!", "", −1)

After the code has been run, the error can be seen by switching over to the Progress tab during execution (see Figure ...

Get Expert SQL Server™ 2005 Integration Services now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.