I am running that uses multiple Foreach Loop Containers and want to run them simultaneously. However, I get the error message -
COM error object information is available. Source:
"ADODB.Recordset" error code: 0x800A0BCD Description: "Either BOF or
EOF is True, or the current record has been deleted. Requested
operation requires a current record."
Obviously, once one Foreach Loop process completes the result set gets dropped.
To get around this I assumed you can pass the same data to different variables like so -
Then in each of the loops just change the DBList, with one Foreach Loop being DBList and the other DBList2 -
However, I receive the error message -
There is an invalid number of result bindings returned for the
ResultSetType: "ResultSetType_Rowset".
Is it impossible to run multiple Foreach Loops concurrently?
You can run foreach loops concurrently, but you have to get your resultset into multiple object type variables and you also have to have 2 sets of variables you would use for the variable mappings for each of the foreach loops.
Example:
Your data flow will consist of a source, multicast and 2 different RecordSet destinations:
The example source here is just returning 1 column of a list of numbers. We multiple cast that into 2 separate RecordSet Destinations that are then assigned to their own object variable type. In this example I have 2 variables, User::RecordSet1 and User:RecordSet2.
Then each of the foreach loops is configured to each of those variables:
Then you have separate variables for each of the foreach loops:
From there you'll need to make sure you're using the appropriate set of variables in whatever code you have in each of the foreach loops.
Instead of using an Execute SQL Task, create a Data Flow, and then use a SQL Query as your Source (probably OLE DB Source). Then pipe that to a Multicast, with outputs to two different Recordset Destinations. In the Component Properties tab, set the VariableName to one of your object variables, then click on the Input Columns to choose which columns you want to include. Do the same for the other Recordset Destination, choosing your second object variable this time, and again selecting which columns to include. Then go back to your Control Flow and link the Data Flow you just created to your two Foreach Loop Container.
Related
I have a simple job that grabs Employee IDs and sends them to an API call, which only accepts one Employee ID at a time. I have this setup using a ForEach Loop Container being fed by an Execute SQL Task.
The job runs as expected, but it is only looping through the top N record.
My Execute SQL Task is returning a full result set to a variable. My variable is set as an Object data type.
I have the ForEach Loop set to Foreach ADO Enumerator, then matched to my variable.
When I run the job I don't get a specific error message telling me what I'm doing wrong, but it fails at the ForEach Loop as shown
Anything else I can look out for?
The Execute SQL Task needs to shove results into an SSIS variable of Object type. I assume associateOID is a string type, yeah?
What you need to do is create an SSIS variable called something like rsEmployees of type Object. Your ResultSet in Execute SQL Task will then map to User::rsEmployees
Change the Foreach Loop ADO enumerator to use the variable User::rsEmployees
At this point, the package will execute and store the results into our rsEmployees variable and then the Foreach enumerator will iterate through the records in our set. The last piece is to do something with the current row. That's where your User::associateOID comes into play.
In the Variable Mappings tab of the Foreach Enumerator, add User::associateOID to ordinal 0. That will provide the linkage between the "current row" that is being shredded in the enumerator and our SSIS variables
I declare two variables as "Object" named a and b,
and have a simple SQL task:.
select code from code_list
Using Full result set, I'm trying to pass the result to the variables declared(a and b),
and use them(a and b) on Script Task with two different foreach loops。But it didn't work.
Script Task: insert the result into two different tables(A and B).
Create 3 variables of type Object, only use one as ResultSet. Then Add a Script Task, and select 3 variables as Read/Write Variables.
Inside the Script Task, Create two DataTable variables, and Fill one table with the ResultSet variable:
SSIS - How to access a RecordSet variable inside a Script Task
Then Copy the first DataTable into the second DataTable Variable using dataTable1.Copy() method
At the end, assign each DataTable to one package Variable.
I am getting below error while running my ssis package.
Error: COM error object information is available. Source: "ADODB.Recordset" error code: 0x800A0BCD Description: "Either BOF or EOF is True, or the current record has been deleted. Requested operation requires a current record.".
I am storing a value in an object variable using RecordSetDestination. And I am passing the object variable in 3 ForEachLoop containers and I am trying to run it parallel. If one of the container is passed then the rest of them getting failed.
Below is the same configuraiton in all 3 ForEachLoop's
Any property needs to change or object variable need to rest or we can't use the object variable for parallel exec in ForEach ADO Enumerator.
Need your input here... Thanks
The problem is the variable for the recordset.
The first option would be you add three data flows like origins pointing each one to a different variable.
The second is adding a multicast in your initial data flow, with three outputs, each one pointing to a different variable.
Then you go to each Foreach Loop Container and set the respective variable in the Enumerator configurarion section.
As Ferdipux proposed, try to run Foreach Loops sequentially. This worked for me.
My SSIS package fails with the error:
The type of the value being assigned to variable differs from the
current variable type.
I declared a variable of type string and corresponding column name in SQL table is varchar(33). If I use data type as object it succeeds but again i need to use the variable value in an expression for connection string and there object type is not supported.
Please help me how to proceed.
Note: The goal of my SSIS package is to get server list from a table (that's where it fails) and execute some script with a foreach loop container in all the servers.
If I'm reading your question right, what you actually need are two variables: one is an Object variable that receives the data from your SQL table, and one is a String value that you will pass to your ForEach loop.
The difference between them is that your Object variable can hold multiple rows, while your String value can only hold a single item at a time. What you will do is declare an Object variable, populate it with a list of the servers, then use a ForEach loop to step through each item in the list, feeding the values one at a time to your String variable. You will then use the String variable to set up the script you mentioned, and execute it once per server.
For further reading, there is an excellent walkthrough here that will give you screenshots and examples of what I am talking about.
I know i am replying to this thread very late, below explanation is for people who see this in future.
I encountered this situation recently. I did the below
Firstly my Record Set Destination Variable of object type. Using For Each Loop container, i mapped each and every row data(with multiple columns) to an variable(s) of OBJECT type. When i use any other datatypes other than OBJECT datatype for variable(s) i got the error as below
Error: ForEach Variable Mapping number 3 to variable "User::EMPID" cannot be applied.
Then I used the variable(s) of object type in my Execute SQL Task and it inserts data successfully without any error.
Thumb Rule: Map Record Set Destination output to the variable of
OBJECT type.
I encountered this situation recently. I did the below
Firstly my Record Set Destination Variable of object type.
Using For Each Loop container, i mapped each and every row data(with multiple columns) to an variable(s) of OBJECT type. When i use any other datatypes other than OBJECT datatype for variable(s) i got the error as below
Error: ForEach Variable Mapping number 3 to variable "User::EMPID" cannot be applied.
Then I used the variable(s) of object type in my Execute SQL Task and it inserts data successfully without any error.
Thumb Rule: Map Record Set Destination output to the variable of OBJECT type.
I've two nested foreach loop containers. Each are looping on different resultsets. I've a script task, within the inner foreach loop container, in which I need to be able to acccess values of current row of both the loops. One way of doing it is using variable mappings on both the loops, but is there a way to access current row from within the script? any ideas?
You can access variables mapped in loop containers in script task via Variables property of the Dts object if you add this variables to ReadOnlyVariables or ReadWriteVariables lists in the Script Task Editor.
Map current row of each loop to variable and then access this variables in script task. Isn't this enough?
Example:
string fileName = (string) Dts.Variables["FileName"].Value;
You can read more here: http://msdn.microsoft.com/en-us/library/ms135941.aspx
Update:
You can map whole row to variable at once. Use Object as variable type and set Index = -1 in Variable mappings in Foreach loop.You should receive enumerator, which type is related to enumerated collection.