VariableDispenser.LockForRead(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将该变量添加到只读访问的锁定变量列表中。
public:
void LockForRead(System::String ^ variable);
public void LockForRead(string variable);
member this.LockForRead : string -> unit
Public Sub LockForRead (variable As String)
参数
- variable
- String
要添加到列表中的变量名称被锁定为只读访问。
示例
以下代码示例创建了 , 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
注解
该方法在首次调用时创建列表,并将给定变量添加到列表中。 在后续调用中,变量会被添加到现有列表中。 该方法实际上并不会锁定该变量。 当你完成创建所需变量列表后,调用 GetVariables 锁定该列表中的变量。 在被呼叫之前GetVariables,可以对 和 LockForWrite 进行任意数量的呼叫LockForRead。
注释
多个客户端可以同时获得一个变量的只读锁。
完成后要成功解除锁,请致电 Unlock。