Поделиться через


Метод LockForWrite

Adds the variable to the list of variables to be locked for read/write access.

Пространство имен:  Microsoft.SqlServer.Dts.Runtime
Сборка:  Microsoft.SqlServer.ManagedDTS (в Microsoft.SqlServer.ManagedDTS.dll)

Синтаксис

'Декларация
Public Sub LockForWrite ( _
    variable As String _
)
'Применение
Dim instance As VariableDispenser
Dim variable As String

instance.LockForWrite(variable)
public void LockForWrite(
    string variable
)
public:
void LockForWrite(
    String^ variable
)
member LockForWrite : 
        variable:string -> unit 
public function LockForWrite(
    variable : String
)

Параметры

  • variable
    Тип: System. . :: . .String
    The name of the variable to add to the list to be locked for read/write access.

Замечания

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 lock the variables, it merely creates the list. 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.

ПримечаниеПримечание

Only one client may acquire a read/write lock on any given variable at one time. Therefore, if only read permission is needed, it is best to use LockForRead to help avoid conflicts in variable access.

If the lock was successful, clear it by calling Unlock.

Примеры

The following code example creates a VariableDispenser and adds two system variables to the list that is locked for reading, and one 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.LockForWrite("User:MyVariable");
            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);
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
 
Namespace Microsoft.SqlServer.SSIS.Sample
    Class Program
        Shared  Sub Main(ByVal args() As String)
            Dim pkg As Package =  New Package() 
            Dim vars As Variables =  Nothing 
            Dim variableDispenser As VariableDispenser =  pkg.VariableDispenser 
            variableDispenser.LockForRead("System::PackageName")
            variableDispenser.LockForRead("System::OfflineMode")
            variableDispenser.LockForWrite("User:MyVariable")
            variableDispenser.GetVariables( vars)
            ' Verify that the variable is locked before unlocking.
            Console.WriteLine("Variables are locked? {0}", vars.Locked)
            Dim myVar As Variable
            For Each myVar In vars
                Console.WriteLine("Name        {0}", myVar.Name)
                Console.WriteLine("Description {0}", myVar.Description)
                Console.WriteLine()
            Next
            ' Use Contains to determine whether indexing can be used.
            Dim pkgName As Boolean =  variableDispenser.Contains("PackageName") 
            Dim qName As String =  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)
        End Sub
    End Class
End Namespace

Sample Output:

Variables are locked? True

Name MyVariable

Description

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