Reputation: 11
I am trying to do what seems simple to me, but can't manage to implement it. I want to increment a simple variable in a Data flow Task...
The variable is set in the ReadWriteVariables, there is no output nor input columns.
This is the end-goal (I'll avoid sharing the monstrosity my current code is) :
public class ScriptMain : UserComponent
{
public override void PostExecute()
{
base.PostExecute();
Variables.intDatasourceUpdated++;
}
}
I suppose I'm missing something (very junior with C# and .Net), so any help would be appreciated.
Edit: I want to increment my "updated" or my "inserted" variables depending on the lookup : lookup printscreen. Here, it is always "updated".
My error is : error printscreen. Note that it says "at Variables.get_intDatasourceInserted()" but I never go to that branch here. So I commented the increment line in the "insert script" and it worked.
But then, when I'll have the "insert" case, as I currently have it deactivated, it won't increment.
Upvotes: 1
Views: 1255
Reputation: 9
Usually this can be done, by defining a new C# variable. Set the value of the SSIS-variable to the new variable and then back again.
// Declare user-defined variable and increase the value by 1
int variableValue = Convert.ToInt32(Dts.Variables["myVariable"].Value);
variableValue++;
// Write the new value back into the variable
Dts.Variables["myVariable"].Value = variableValue;
Upvotes: 0
Reputation: 5594
You need to decalre the variable outside of row processing.
public int counter = 0;
public void main()
{
counter++;
}
And at the end set the variable to counter.
post execute...
Variables.Counter = counter;
Upvotes: -1
Reputation: 1479
"The collection of variables locked for read and write access is not available outside of PostExecute".
You are posting your "Update" snippet, the error is saying you are trying to update intDatasourceInserted which likely in your "Insert"s PreExecute(). Which isn't allowed.
In either case you'll still have an issue, since each task there execute simultaneously, waiting for pipeline data, and variables don't work well between tasks inside one data flow, you'll probably need to mangle the data itself as it flows or access the altered variable outside the data flow in the control flow.
Upvotes: 1