VariableDispenser.LockForRead Method
Adds the variable to the list of variables to be locked for read-only access.
Namespace: Microsoft.SqlServer.Dts.Runtime
Assembly: Microsoft.SqlServer.ManagedDTS (in Microsoft.SqlServer.ManagedDTS.dll)
This method, on its first call, creates a list and adds the given variable to the list. On subsequent calls, variables are added to the existing list. This method does not actually lock the variable. When you are done creating a list of the variables you want, call GetVariables to lock the variables that are found in this list. Any number of calls to LockForRead and LockForWrite can be made before GetVariables is called.
Note
|
|---|
|
Multiple clients may simultaneously acquire a read-only lock on a variable. |
To clear a successful lock when you are finished, call Unlock.
The following code example creates a VariableDispenser and adds two system variables to the list that is locked for reading, and one system variable to the list that is locked for writing. Then the GetVariables is called to lock all three variables in the collection, and the lists are freed and made available for new variables.
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.GetVariables(ref vars); // Verify that the variable is locked before unlocking. Console.WriteLine("Variables are locked? {0}", vars.Locked); foreach (Variable myVar in vars) { Console.WriteLine("Name {0}", myVar.Name); Console.WriteLine("Description {0}", myVar.Description); Console.WriteLine(); } // Use Contains to determine whether indexing can be used. Boolean pkgName = variableDispenser.Contains("PackageName"); String qName = variableDispenser.GetQualifiedName("PackageName"); Console.WriteLine("Contains is valid? {0}", pkgName); Console.WriteLine("Fully qualified name is: {0}", qName); vars.Unlock(); Console.WriteLine("Variables are locked? {0}", vars.Locked); } } }
Sample Output:
Variables are locked? True
Name OfflineMode
Description The offline mode currently set for the package
Name PackageName
Description The package name
Contains is valid? True
Fully qualified name is: System::PackageName
Variables are locked? False
Note