November 12, 2011

A deadlock was detected error

A good friend of mine call me in a desperate mode because of an particular problem they have added some changes and now the package is failing because of a deadlock against some of the variables in the package.

After some thoughts I ask how he was typically adding the variables into the ReadWriteVariables like most users,  once he said that I said "Oh Nooo" even thought that made things simple is not always the best way to ensure deadblock will happen so. I said remove the variables from the ReadWriteVariables and modify your code using the below sample code:

 Variables var = null ;
        
           Dts.VariableDispenser.LockForWrite ("User::int_Sample1");
           Dts.VariableDispenser.LockForWrite ("User::int_Sample2");
           Dts.VariableDispenser.LockForWrite ("User::dt_today");
            Dts.VariableDispenser.GetVariables (ref var );
           var["User::int_Sample1"].Value = 1;
           var["User::int_Sample2"].Value = 2;
           var["User::dt_today"].Value = DateTime.Now;

           var.Unlock();
                 Dts.TaskResult = (int)ScriptResults.Success;

He was delighted, and I explain to him developers need to act like mechanics, we love the new tools, but, once in awhile look inside the engine to get your hands dirty...

No comments:

Post a Comment

Contact Form

Name

Email *

Message *