Recently I found this issue of deadlock variables in SSIS and finally made two solutions
1. Instead of declaring variables in Script properties (ReadOnlyVariables / ReadWriteVariables), better to make use of Dts.VariableDispenser.LockForRead / Dts.VariableDispenser.LockForWrite in the script to lock variables
2. I also solved my problem by running child packages out-of-proc (ExecuteOutOfProcess=TRUE in Execute Package Task), this is more to do with script caching
But recently I saw something strange and found out that one of my script is making use of this type of code and I am getting this error again.....
"The script threw an exception: A deadlock was detected while trying to lock variables "variable names (comma separated)" for read access and variables "variable names (comma separated)" for read/write access. A lock cannot be acquired after 16 attempts. The locks timed out."
Dim var As Variables
Dts.VariableDispenser.LockForWrite("User::VarName")
Dts.VariableDispenser.GetVariables(var)
'Problem Line, Just remove the reference to Dts.Variables
Dts.Variables("User::VarName").Value = "SomeVal"
'Correct Line, make use of locally declared "var" Variable
var("User::VarName").Value = "SomeVal"
var.Unlock()
To solve the situation I made a quick fix and change my Dts.Variables to local variable collection I defined in the beginning "var".
As we can see in this script that we are locking one variable for write. But after using the GetVariables we MUST use "var" collection to write data and should NOT use Dts.Variables and that fixed my problem.
So I think this is some sort of double locking issue, like if I lock the variable using "Dts.VariableDispenser" and if I try to access the same variable again with Dts.Variables instead of "var" then SSIS tries to lock that again......
- Mohit Nayyar
1 comment:
nice
Post a Comment