Mohamed Mekdad
Mohamed Mekdad

Reputation: 113

Update a variable in SSIS Custom component not persistent as the process terminates

i am currently developing a ssis custom component , in the design time i create a user variable and update it any time i want perfectly.

Now, when i execute the package, and in the PrimeOutput method i update the variable successfully, but when the process terminates the variable is not persistent and the only value i get is the old value. here is how i update the variable :

IDTSVariables100 variables = null;
VariableDispenser.LockOneForWrite(name, ref variables);
variables[name].Value = newValue;
variables.Unlock();

Upvotes: 2

Views: 780

Answers (1)

Hadi
Hadi

Reputation: 37358

Assuming that your variable name is MyVar

 VariableDispenser variableDispenser = (VariableDispenser)this.VariableDispenser;
 variableDispenser.LockForWrite("User::myVar");

 IDTSVariables100 vars;
 variableDispenser.GetVariables(out vars);

 // Set the variable
 vars["User::myVar"].Value = newValue;

 // Unlock the variable
 vars.Unlock();

For more info you can refer to this useful links:

Update 1

After reading your comment "but after the package finish executing, the variable reset to the old value"

The variable value stored in the package file by default is the one you specified when designing the package (programmatically or using visual studio)

Also if changing the variable value inside a script it will change the value only when executing, and the new value cannot be readed from another component inside the same DataFlow Task the value will be committed when the Current DataFlow Task finished executing

Useful Links

If you are interested to edit packages programmatically you can refer to the following links

Upvotes: 1

Related Questions