7
votes

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?

2
Please confirm your observed behavior: does the task "not fail immediately", or does the task "not fail at all"? - Todd McDermid

2 Answers

2
votes

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.

1
votes

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);