0

i am processing a ragged semicolon delimited file using script component as transformation.

The component is able to process the data and load to oledb destination. But when error is found it should stop processing further. As i am using try catch block the component doesn't fail and continue to process till the end.

Is there any way i could stop the processing further without failing the component/package?

Let me know if any other information/details required?

sample code:

str.split(";");

if(column[0] == "H")
{
col1=Column[3];
}

if(column[0] != "T")
{
try
{
Row.col1=Column[0];
Row.col2=Column[1];
.....
}
catch
{
update the variable to check if we have error in file.
}
}

Thank you for your time.

Linu1988
  • 49
  • 3
  • 8

2 Answers2

0

The general idea will be that you want to use try/catch blocks to ensure the data processing itself doesn't abort. Once you know your script isn't reporting a failure back to the engine, it's a simple process to not call the AddRow()

Pseudocode

foreach(line in fileReader)
{
    try
    {
        // perform dangerous operations here
        // Only add row if you have been able to parse current line
        Output0Buffer.AddRow();
        Output0Buffer.Col1 = parsedContent;
    }
    catch
    {
        // Signal that we should break out of the loop
        // do not propagate the error
        // You might want to do something though so you know you 
        // have an incomplete load
        break;
    }

}

If you are looking to just skip the current bad line, you can substitute continue for the break above.

C# loop - break vs. continue

Community
  • 1
  • 1
billinkc
  • 59,250
  • 9
  • 102
  • 159
  • I have updated the original question by giving a sample code. I am using synchronous script component as transformation, so i dont think i need a loop inside that. Could you tell anyway i can stop it whenever i get an exception, in the catch block? Thanks – Linu1988 Sep 26 '13 at 20:03
  • Billinkc could you please take a look for the above scenario? Have you come across the above scenario? Thanks – Linu1988 Sep 29 '13 at 17:55
0

I didn't get any help from anywhere, But as a work around i have placed a return statement in the code. It checks the error variable if it's true then i will return without processing further. But the thing still is it processes the whole file :(. But it works!!!

Linu1988
  • 49
  • 3
  • 8