Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Variables.Unlock Method

Releases the locks on the variables collection and flags the state of the variables collection as invalid or unknown.

Namespace:  Microsoft.SqlServer.Dts.Runtime
Assembly:  Microsoft.SqlServer.ManagedDTS (in Microsoft.SqlServer.ManagedDTS.dll)
public void Unlock()

This method is used to unlock variables that were locked by using the VariableDispenser class. When VariableDispenser dispenses a variables collection, it keeps track of the collection in a list. When the task that called the variable dispenser finishes executing, all dispensed collections are automatically unlocked. Therefore, if automatic unlocking is suitable for your purposes, and if automatic unlocking occurred when the task completed, you do not need to call the Unlock method. However, it is sometimes desirable to unlock variables as soon as possible for performance reasons. An explicit call to this Unlock method unlocks the variables.

The Locked property returns a value of false to indicate that a dispensed collection has already been unlocked. A value of true indicates that the variable collection is still locked. Calling Unlock twice causes an error; therefore, in certain situations you may have to check the value of this property before deciding whether to call Unlock.

The following code example locks the variable collection when GetVariables is called. The example then checks if the collection is locked and, if so, calls Unlock.

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;

namespace Microsoft.SqlServer.SSIS.Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            Package pkg = new Package();
            Variables vars = null;
            VariableDispenser variableDispenser = pkg.VariableDispenser;
            variableDispenser.LockForRead("System::PackageName");
            variableDispenser.LockForRead("System::OfflineMode");
            variableDispenser.LockForWrite("System::InteractiveMode");
            variableDispenser.GetVariables(ref vars);           
            // Determine whether the variable collection is locked before unlocking.
            Boolean isLocked = vars.Locked;

            // Verify the value of vars.Locked. If the lock failed,
            // call Reset.
            if (isLocked)
            {
                vars.Unlock();
            }
            else
            {
                variableDispenser.Reset();
            }
        }
    }
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.