Thursday 18 March 2021

Fail package forcefully at run time based on the condition

In the previous post, we see how we can fail our package using the ForceExecutionResult property at the run time.

Read here: Set ForceExecutionResult value during the Runtime (Fail package forcefully at run time based on the condition)

https://bageshkumarbagi-msbi.blogspot.com/2021/03/set-forceexecutionresult-value-during.html

In this post, we will see how we can fail our package using the script task.

Below is the package design  


In the script task, we are writing the below code.

public void Main()

                {

                                                // TODO: Add your code here

            int error_count;

            error_count = int.Parse(Dts.Variables["User::Error_Count"].Value.ToString());

            if (error_count > 0)

            {

                Dts.TaskResult = (int)ScriptResults.Failure;

            }

            else

            {

                Dts.TaskResult = (int)ScriptResults.Success;

            }

}

Basically here we are checking the count of the error log. If it is greater than 0 in this case we are failing the package and if not then we are executing the remaining task.

Now we are running this corrupted data.

File data   

Running the package.  

Package failed.

Now we are correcting the data and running this package.    

Running the package now.   

Package executed successfully.

Both ways we can our Fail package forcefully at run time.

No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts