Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SSIS - How to make script component fail task?

I have a Script component (Script Transformation), which I need to be able to fail the DFT, i.e. the Data Flow Task that it is part of.

I am firing an error like this

try
{
   // Does some work here, which can fail...
}
catch (Exception ex)
{
   bool pbCancel = false;
   this.ComponentMetaData.FireError(0, Variables.TaskName, "Error message: " + ex.Message, String.Empty, 0, out pbCancel);
}

However, FireError does not cause the task to fail.

Note that this is a script component inside a data transformation task - not a script task.

What do I do to fail this task from the script component?

like image 501
Anders Avatar asked Jun 18 '13 08:06

Anders


People also ask

What is the difference between script task and script component?

A Script task runs custom code at some point in the package workflow. Unless you put it in a loop container or an event handler, it only runs once. A Script component also runs once, but typically it runs its main processing routine once for each row of data in the data flow.

What is the use of script component in SSIS?

The Script Component provides another area where programming logic can be applied in an SSIS package. This component, which can be used only in the Data Flow portion of an SSIS package, allows programmatic tasks to occur in the data stream. This component exists to provide, consume, or transform data using . NET code.

What is DTS in SSIS script task?

The Dts object is an instance of the ScriptObjectModel class. ScriptTask. Defines the classes for the Script task, which lets developers write custom code to perform functions that are not available in the built-in tasks provided by Integration Services.

How do I create a script task in SSIS package?

Configuring the Script TaskProvide the custom script that the task runs. Specify the method in the VSTA project that the Integration Services runtime calls as the entry point into the Script task code. Specify the script language. Optionally, provide lists of read-only and read/write variables for use in the script.


2 Answers

In your example you are catching the exception but not throwing it. Just add

catch (Exception ex)
{
    // ... your other code here
    throw ex;
}

and the component will fail.

like image 55
codeMonkey Avatar answered Sep 28 '22 16:09

codeMonkey


This should be what you're looking for - 2008 R2 C# script component.

bool fireAgain = true;
IDTSComponentMetaData100 myMetaData;
myMetaData = this.ComponentMetaData;

//for information
myMetaData.FireInformation(0, "SubComponent", "Description", string.Empty, 0, ref fireAgain);
//for error
myMetaData.FireError(0, "SubComponent", ex.Message.ToString() + ex.StackTrace, string.Empty, 0, out fireAgain);
like image 23
esre Avatar answered Sep 28 '22 16:09

esre