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 ()
public void Unlock ()
public function 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.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)

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Development Platforms

For a list of the supported platforms, see Hardware and Software Requirements for Installing SQL Server 2005.

Target Platforms

Community Additions