0

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:

  1. Adding an OnTaskFailed event handler to the Script task
  2. Adding an OnError event handler to the script task

Outcome has been as follows:

  1. 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.

  2. 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

JosePaya
  • 323
  • 3
  • 7
  • Please ignore the line that refers to the fileName variable. It is not used for anything in the package – JosePaya Jan 20 '20 at 15:59
  • I will add to my initial explanation. The whole thing is for testing purposes of a ScriptTask failing within a foreach Loop. I want to handle the failure results with an event handler that will change the propagate variable value to "False" preventing the failure from bubbling up to the container, and therefore forcing the loop to move to the next iteration. But why is it only the OnError event handler that picks this ScriptTask failure result? – JosePaya Jan 20 '20 at 16:11
  • I'm nowhere near being a C# developer, but I think I may have had a similar problem. Long answer short, I changed my code to use `this.Dts.{whatever}`. Check out my question and self answer here: https://stackoverflow.com/questions/51753727/how-do-i-use-dts-events-fireinformation-in-ssis-script-task-while-handling-win – digital.aaron Jan 21 '20 at 19:15

0 Answers0