ErrorEnumerator.Current 属性
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取集合中的当前 DtsError 元素。
public:
property Microsoft::SqlServer::Dts::Runtime::DtsError ^ Current { Microsoft::SqlServer::Dts::Runtime::DtsError ^ get(); };
public Microsoft.SqlServer.Dts.Runtime.DtsError Current { get; }
member this.Current : Microsoft.SqlServer.Dts.Runtime.DtsError
Public ReadOnly Property Current As DtsError
属性值
集合中的当前 DtsError 元素。
示例
下面的代码示例将任务添加到包,然后运行包。 通过创建 ErrorEnumerator 并显示每个错误说明来显示警告集合。
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Tasks.SendMailTask;
namespace Microsoft.SqlServer.SSIS.Samples
{
class Program
{
static void Main(string[] args)
{
Package package = new Package();
Console.WriteLine("Package errors count before running: {0}", package.Errors.Count);
TaskHost taskH2 = (TaskHost)package.Executables.Add("STOCK:SendMailTask");
taskH2.FailPackageOnFailure = false;
taskH2.FailParentOnFailure = false;
Console.WriteLine("SendMailTask: {0}", taskH2.ID);
// Test that warnings were successfully added to the collection.
package.MaximumErrorCount = 100;
package.FailPackageOnFailure = false;
package.FailParentOnFailure = false;
package.DelayValidation = true;
package.Execute();
Console.WriteLine("Package errors count after running the package: {0}", package.Errors.Count);
// Create the enumerator.
ErrorEnumerator myEnumerator = package.Errors.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.Description);
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Tasks.SendMailTask
Namespace Microsoft.SqlServer.SSIS.Samples
Class Program
Shared Sub Main(ByVal args() As String)
Dim package As Package = New Package()
Console.WriteLine("Package errors count before running: {0}", package.Errors.Count)
Dim taskH2 As TaskHost = CType(package.Executables.Add("STOCK:SendMailTask"), TaskHost)
taskH2.FailPackageOnFailure = False
taskH2.FailParentOnFailure = False
Console.WriteLine("SendMailTask: {0}", taskH2.ID)
' Test that warnings were successfully added to the collection.
package.MaximumErrorCount = 100
package.FailPackageOnFailure = False
package.FailParentOnFailure = False
package.DelayValidation = True
package.Execute()
Console.WriteLine("Package errors count after running the package: {0}", package.Errors.Count)
' Create the enumerator.
Dim myEnumerator As ErrorEnumerator = package.Errors.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
SendMailTask: {DE20010F-928A-4E9B-B57F-71D7991EC8F0}
运行包后包错误计数:3
该集合包含以下值:
[0] 未指定 SMTP 服务器
[1] 未指定收件人
[2] 任务验证期间出错。
注解
创建枚举器或调用 Reset
方法后, MoveNext
必须调用该方法,以便将枚举器提升到集合的第一个元素,然后枚举器才能读取属性的值 Current ;否则, Current 未定义并引发异常。
Current如果最后一次调用返回false
,则还会引发异常,该调用MoveNext
指示集合的末尾。
Current 不会移动枚举器的位置,并且连续调用以 Current 返回同一对象,直到 MoveNext
调用或 Reset
调用。
只要集合保持不变,枚举器就仍有效。 如果对集合进行了更改(如添加、修改或删除元素),则枚举器将失效并变为不可恢复;因此,下一次调用 MoveNext
或 Reset
引发一个 InvalidOperationException
。 如果在调用和Current调用MoveNext
之间修改集合,Current则返回它设置为的元素,即使枚举器已失效。