Monday 7 October 2019

Dts.Events.FireError method in Script task in SSIS


When we are using the script task or script component and we want to fire the error log in this case we need to fire the error event method.

Let’s see the example.


Here I am taking script task and writing the below C# code to raise the error.
int i = 1;
            int n = 0;
            bool fireAgain = true;
            try
            {
                for (i = 1; i <= 10; i++)
                {
                    Dts.Events.FireInformation(0, "Fire Information", "Count : " + i.ToString(), string.Empty, 0, ref fireAgain);
                    if (i == 5)
                    {
                        n = n / 0;
                    }
                }
            }
            catch(Exception ex)
            {
                Dts.Events.FireError(0, "Fire Error", "An error occurred: " + ex.Message.ToString(), "", 0);
                Dts.TaskResult = (int)ScriptResults.Failure;
            }

When I value will reach to 5 then it will throw an error.
Now I am executing this task.
OOOOOOO this package is failed.


See the error log.



No comments:

Post a Comment

If you have any doubt, please let me know.

Popular Posts