ConnectionEnumerator.Current 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
从 ConnectionManager 集合获取当前的 Connections 对象。
public:
property Microsoft::SqlServer::Dts::Runtime::ConnectionManager ^ Current { Microsoft::SqlServer::Dts::Runtime::ConnectionManager ^ get(); };
public Microsoft.SqlServer.Dts.Runtime.ConnectionManager Current { get; }
member this.Current : Microsoft.SqlServer.Dts.Runtime.ConnectionManager
Public ReadOnly Property Current As ConnectionManager
属性值
示例
下面的代码示例创建一个枚举器,然后使用 Current 和 MoveNext 方法在集合中导航。
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
namespace ConnMgr_GetEnum_Current
{
class Program
{
static void Main(string[] args)
{
// The package is one of the SSIS Samples.
string mySample = @"C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx";
// Create the application, and load the sample.
Application app = new Application();
Package pkg = app.LoadPackage(mySample, null);
// Get the Connections collection from the package.
Connections conns = pkg.Connections;
//Create the Enumerator.
ConnectionEnumerator myEnumerator = conns.GetEnumerator();
Console.WriteLine("The collection contains the following values:");
int i = 0;
while ((myEnumerator.MoveNext()) && (myEnumerator.Current != null))
Console.WriteLine("[{0}] {1}", i++, myEnumerator.Current.Name);
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
Namespace ConnMgr_GetEnum_Current
Class Program
Shared Sub Main(ByVal args() As String)
' The package is one of the SSIS Samples.
Dim mySample As String = "C:\Program Files\Microsoft SQL Server\100\Samples\Integration Services\Package Samples\CalculatedColumns Sample\CalculatedColumns\CalculatedColumns.dtsx"
' Create the application, and load the sample.
Dim app As Application = New Application()
Dim pkg As Package = app.LoadPackage(mySample,Nothing)
' Get the Connections collection from the package.
Dim conns As Connections = pkg.Connections
'Create the Enumerator.
Dim myEnumerator As ConnectionEnumerator = conns.GetEnumerator()
Console.WriteLine("The collection contains the following values:")
Dim i As Integer = 0
While (myEnumerator.MoveNext()) &&(myEnumerator.Current <> Nothing)
Console.WriteLine("[{0}] {1}",i = Console.WriteLine("[{0}] {1}",i + 1
End While
End Sub
End Class
End Namespace
示例输出:
该集合包含以下值:
[0] localhost。AdventureWorks
[1] 事务摘要(按 Product1)
注解
在创建枚举器后,或在调用 Reset 方法后, MoveNext 必须调用方法以将枚举数前移到集合的第一个元素,然后再读取属性的值 Current ; 否则, Current 将为 undefined,并引发异常。
Current如果最后一次调用 MoveNext 返回 false (指示集合的末尾),也会引发异常。
Current不移动枚举器的位置,并且连续调用将 Current 返回相同的对象,直到 MoveNext Reset 调用或。
只要集合保持不变,枚举器就仍有效。 如果对集合所做的更改(如添加、修改或删除元素),则枚举器将失效并且不可恢复;因此,对或的下一个调用将 MoveNext Reset 引发 InvalidOperationException 。 如果在对和的调用之间修改 MoveNext 集合 Current ,则 Current 将返回它设置为的元素,即使枚举器已失效。