SSIS - How to make script component fail task?
Asked Answered
S

2

7

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?

Substandard answered 18/6, 2013 at 8:58 Comment(1)
Please confirm your observed behavior: does the task "not fail immediately", or does the task "not fail at all"?Tessatessellate
P
2

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.

Propitious answered 28/3, 2019 at 16:50 Comment(0)
T
1

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);
Tinkling answered 3/11, 2014 at 18:12 Comment(1)
In SSDT 2017, this creates an observable error but does not fail the component.Propitious

© 2022 - 2025 — McMap. All rights reserved.