VariableDispenser.GetVariables(Variables) 方法

定义

锁定只读列表和读/写列表中的变量。

public:
 void GetVariables(Microsoft::SqlServer::Dts::Runtime::Variables ^ % variables);
public void GetVariables (ref Microsoft.SqlServer.Dts.Runtime.Variables variables);
member this.GetVariables : Variables -> unit
Public Sub GetVariables (ByRef variables As Variables)

参数

variables
Variables

包含在只读列表和读/写列表中找到的所有变量的集合。

示例

下面的代码示例创建一个并将两个 VariableDispenser 系统变量添加到锁定以供读取的列表。 GetVariables然后调用该函数来锁定集合中的两个变量,并释放列表并可用于新变量。

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);  
        }  
    }  
}  
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.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  

示例输出:

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

注解

调用此方法可锁定以前添加到只读列表或读/写列表的所有变量。

如果调用成功,则释放列表,并将请求的变量合并到单个集合中,每个变量都锁定为指定的访问。 若要解锁变量,请使用集合释放Variables变量集合Unlock

如果调用失败,列表将保持不变,但变量不会锁定。

注意

对于所需的最短时间,最好对变量保持锁。 这样,其他组件和任务就可以获取锁并方便共享变量。

适用于