Package.Execute 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回一个 DTSExecResult 枚举,其中包含有关包执行成功与否的信息。
public:
Microsoft::SqlServer::Dts::Runtime::DTSExecResult Execute();
public Microsoft.SqlServer.Dts.Runtime.DTSExecResult Execute ();
override this.Execute : unit -> Microsoft.SqlServer.Dts.Runtime.DTSExecResult
Public Function Execute () As DTSExecResult
返回
一个 DTSExecResult 枚举,其中包含有关包执行成功与否的信息。
示例
下面的代码示例创建包,在 OfflineMode 添加脚本任务之前设置和 InteractiveMode 属性。 然后,它使用 Execute 该方法运行包。
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Dts.Runtime;
using Microsoft.SqlServer.Dts.Tasks.ScriptTask;
namespace Package_API
{
class Program
{
static void Main(string[] args)
{
Package p = new Package();
p.InteractiveMode = true;
p.OfflineMode = true;
// Add a Script Task to the package.
TaskHost taskH = (TaskHost)p.Executables.Add(typeof(Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptTask).AssemblyQualifiedName);
// Run the package.
p.Execute();
// Review the results of the run.
if (taskH.ExecutionResult == DTSExecResult.Failure || taskH.ExecutionStatus == DTSExecStatus.Abend)
Console.WriteLine("Task failed or abended");
else
Console.WriteLine("Task ran successfully");
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.SqlServer.Dts.Runtime
Imports Microsoft.SqlServer.Dts.Tasks.ScriptTask
Namespace Package_API
Class Program
Shared Sub Main(ByVal args() As String)
Dim p As Package = New Package()
p.InteractiveMode = True
p.OfflineMode = True
' Add a Script Task to the package.
Dim taskH As TaskHost = CType(p.Executables.Add(Type.GetType(Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptTask).AssemblyQualifiedName), TaskHost)
' Run the package.
p.Execute()
' Review the results of the run.
If taskH.ExecutionResult = DTSExecResult.Failure Or taskH.ExecutionStatus = DTSExecStatus.Abend Then
Console.WriteLine("Task failed or abended")
Else
Console.WriteLine("Task ran successfully")
End If
End Sub
End Class
End Namespace
注解
该方法 Execute 由任务主机和其他对象从抽象类继承 Executable ,通过 DtsContainer 类继承,并允许由运行时引擎运行继承对象。
Execute单个对象继承的方法在代码中不常用,如果需要在包中运行任何任务或容器,建议调用Execute该方法。 但是, Execute 如果发现需要该方法的唯一情况,则可以对各个对象使用该方法。
此方法 Execute 的主要用途是在创建自定义任务时继承和重写该方法。 有关如何重写 Execute 方法的详细信息,请参阅 对自定义任务进行编码。
该方法 Execute 在包运行之前隐式调用 Validate 该方法。 包中的所有任务都会在验证期间查看相应的设置,并查看包中的所有对象,包括包中的包、容器和其他组件。
如果在验证阶段没有遇到导致包失败的问题,包对象将继续调用 Execute 包中的每个任务和对象的方法。
null当属性为 false. 时TransactionOption传递transaction参数。
TransactionOption如果属性为 true,则可以传入nulltransaction参数以指示容器支持事务,但不参与。