1

Thank you for answering the question.

I check whether the variables contains null, however it's not the cause of null.

Today, I find out why can not work. Because, the variable I set at variable mapping is as same as collection one too. So first loop works but next loop doesn't work.

when I set different variable at variable mapping, it works completely.

I apologize for careless mistake.


I'm using SSIS 2008. I get two kind of data, date(4/1,4/2,4/3) and number(10,20,30) from text file.

I input them at variables as array and object typed.

I tried to loop them by using foreach loop container. I put the array at enumerator from variables. I confirm it loops and show the message 4/1,4/2,4/3 by using msgbox. it success to loop.

I try to loop different variables of number by above same way. it success to show 10,20,30.

howwever, I set the foreach loop container of date in the foreach container of number. the msgbox show 10 4/1, 10 4/2, 10 4/3 at first, but next is empty message, then under error occurred

Error: The GetEnumerator method of the ForEach Enumerator has failed with error 0x80131509 "(null)". This occurs when the ForEach Enumerator cannot enumerate.

more information, when debug, the two foreach loop container is red, but the script task of msgbox in the two containers is green.

I'd like to know why and how to solve the problem.

2 Answers 2

1

I had this Problem. I solved it by applying the parameter values to an "Foreach ADO Enumerator" in "Foreach Loop Editor" window.

Foreach Loop Editor

Hope it helps.

0

I reviewed your updated question and the cause is definitely due to your attempting to enumerate an object variable containing a NULL. As you stated when applying the message box in a script task, one of the values is "empty" and that is when the error takes place and the ForEach loop changes to Red. The ForEach loop changes to Red because it cannot enumerate a NULL.

There are two options for resolving this issue:

  1. At the point where the values are assigned into the object variable (which is an array), apply a condition that checks for null values. If not NULL, add or insert to the object (array) variable.
  2. Apply an expression in the nested ForEach loop that uses the built-in functions to check for a null and change it to something like 0 (zero). You may need to apply the expression on the ForEachEnumerator Property so that the value sent to Variable Mappings is not a NULL. This will require some experimentation.

If you were reading from a database table, this would be easily resolved with a SQL statement applying the ISNULL function to check for a NULL and change it to something else. In your case, you are reading from a text file and need to find a way to programmatically do the same with C# or VB.NET with regard to how an array of values is saved to the object variable.

Hope this helps. Please mark my response as having answered your question if it helped. Thanks.

1
  • Point 2 applies to me in my case. I have variable to enumerate but need to do NULL check before the ForEach loop begins. How to do that? My User::Variable is of type Object. The setting ISNULL() expression is not identifying the variable type.
    – meekash55
    Sep 29, 2021 at 10:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.