This is something that is really down to fairly advance knowledge of the .NET framework but I haven't been able to find the information I needed.
I have an SSIS package that executes a ScriptTask. Within that ScriptTask the below simple code:
public void Main()
{
// TODO: Add your code here
var fileName = (string)Dts.Variables["User::FileName"].Value;
DialogResult result = MessageBox.Show($"Do you want to fail the task", "Select what to do" , MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
Dts.TaskResult = (int)ScriptResults.Failure;
} else
{
Dts.TaskResult = (int)ScriptResults.Success;
}
}
As you can see, it quite difficult to write any simpler code. My question is around the event handler for this script task.
I have tried the following:
- Adding an
OnTaskFailed
event handler to the Script task - Adding an
OnError
event handler to the script task
Outcome has been as follows:
Event handler does not trigger, meaning that the task result returned by
Dts.TaskResult = (int)ScriptResults.Failure;
does not have an impact to the package.Event handler does trigger, meaning that the task result returned by
Dts.TaskResult = (int)ScriptResults.Failure;
is captured by the event handler.
I would have expected to be the other way around. Can anyone explain why this is the case? To me OnError
is a more generic outcome and I wouldn't like my event handler to trigger on every single error (e.g. unhandled exceptions).
Hope this makes sense