ScriptTask.Execute(Connections, VariableDispenser, IDTSComponentEvents, IDTSLogging, Object) Method

Definition

执行此 DTS 脚本任务实例中包含的脚本。Executes the script contained in this instance of DTS Script Task.

public:
 override Microsoft::SqlServer::Dts::Runtime::DTSExecResult Execute(Microsoft::SqlServer::Dts::Runtime::Connections ^ connections, Microsoft::SqlServer::Dts::Runtime::VariableDispenser ^ variableDispenser, Microsoft::SqlServer::Dts::Runtime::IDTSComponentEvents ^ events, Microsoft::SqlServer::Dts::Runtime::IDTSLogging ^ log, System::Object ^ transaction);
public override Microsoft.SqlServer.Dts.Runtime.DTSExecResult Execute (Microsoft.SqlServer.Dts.Runtime.Connections connections, Microsoft.SqlServer.Dts.Runtime.VariableDispenser variableDispenser, Microsoft.SqlServer.Dts.Runtime.IDTSComponentEvents events, Microsoft.SqlServer.Dts.Runtime.IDTSLogging log, object transaction);
override this.Execute : Microsoft.SqlServer.Dts.Runtime.Connections * Microsoft.SqlServer.Dts.Runtime.VariableDispenser * Microsoft.SqlServer.Dts.Runtime.IDTSComponentEvents * Microsoft.SqlServer.Dts.Runtime.IDTSLogging * obj -> Microsoft.SqlServer.Dts.Runtime.DTSExecResult
Public Overrides Function Execute (connections As Connections, variableDispenser As VariableDispenser, events As IDTSComponentEvents, log As IDTSLogging, transaction As Object) As DTSExecResult

Parameters

connections
Connections

任务使用的连接的集合。A collection of connections used by the task.

variableDispenser
VariableDispenser

一个用来锁定变量的 VariableDispenser 对象。A VariableDispenser object for locking variables.

events
IDTSComponentEvents

一个实现 IDTSComponentEvents 接口的对象。An object that implements the IDTSComponentEvents interface.

log
IDTSLogging

一个实现 IDTSLogging 接口的对象。An object that implements the IDTSLogging interface.

transaction
Object

容器所属的事务对象。The transaction object that the container is a part of. 运行时基于 TransactionOption 属性提供容器的事务。The runtime provides the transaction for the container, based on the TransactionOption property. 此值可以为 null。This value can be null.

Returns

DTSExecResult

一个来自 DTSExecResult 枚举的值。A value from the DTSExecResult enumeration.

Examples

下面的代码示例演示如何在 BulkInsertTask 设置了一些任务属性后运行包含的包。The following code example shows how to run a package that contains a BulkInsertTask after some of the task properties are set. 大容量插入任务就是此代码示例的示例;可以创建任何任务。The Bulk Insert task is just an example for this code sample; any task can be created.

using System;  
using System.Collections.Generic;  
using System.Text;  
using Microsoft.SqlServer.Dts.Runtime;  
using Microsoft.SqlServer.Dts.Tasks.BulkInsertTask  
  
namespace Microsoft.SqlServer.SSIS.Samples  
{  
    class Program  
    {  
        static void Main(string[] args)  
        {  
            Package p = new Package();  
            p.InteractiveMode = true;  
            p.OfflineMode = true;  
            Executable exec1 = pkg.Executables.Add("STOCK:BulkInsertTask");  
            TaskHost th = exec1 as TaskHost;  
  
            // Set the CheckConstraints and DataFileType properties.             
            th.Properties["CheckConstraints"].SetValue(th, true);  
            th.Properties["DataFileType"].SetValue(th, DTSBulkInsert_DataFileType.DTSBulkInsert_DataFileType_Native);  
  
            // Run the package that contains the task.  
            pkg.Execute();  
  
            // Review the results of execution.  
            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.BulkInsertTask  
  
Namespace Microsoft.SqlServer.SSIS.Samples  
    Class Program  
        Shared  Sub Main(ByVal args() As String)  
            Dim p As Package =  New Package()   
            p.InteractiveMode = True  
            p.OfflineMode = True  
            Dim exec1 As Executable =  pkg.Executables.Add("STOCK:BulkInsertTask")   
            Dim th As TaskHost =  exec1 as TaskHost   
  
            ' Set the CheckConstraints and DataFileType properties.             
            th.Properties("CheckConstraints").SetValue(th, True)  
            th.Properties("DataFileType").SetValue(th, DTSBulkInsert_DataFileType.DTSBulkInsert_DataFileType_Native)  
  
            ' Run the package that contains the task.  
            pkg.Execute()  
  
            ' Review the results of execution.  
            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  

Remarks

Execute方法由任务宿主和抽象类中的其他对象 Executable 通过类继承, DtsContainer 并使继承对象可由运行时引擎运行。The Execute method is inherited by task hosts and other objects from the Executable abstract class, through the DtsContainer class, and enables the inheriting objects to be run by the run-time engine. Execute各个对象继承的方法通常不在代码中使用, Execute 如果必须在包中运行任务或容器,则应调用方法。The Execute method inherited by the individual objects is not ordinarily used in code, and you should call the Execute method if you have to run tasks or containers in the package. 但是, Execute 如果你发现需要它的独特情况,则该方法可用于单个对象。However, the Execute method is available on individual objects if you find a unique circumstance where it is required.

Execute方法在 Validate 包运行之前隐式调用方法。The Execute method calls the Validate method implicitly before the package runs. 在验证过程中,将检查包中的所有任务是否有适当的设置,并检查包中的所有对象,包括包、容器和包中的其他组件。All tasks in the package are reviewed for appropriate settings during validation, and all objects in the package are reviewed, including the package, containers, and other components in the package.

如果验证阶段中没有出现导致包失败的问题,package 对象将 Execute 为包中的每个任务和对象调用方法。If there are no problems encountered in the validation phase that would cause the package to fail, the package object calls the Execute method for each task and object in the package.

null transaction 当属性为时,传递给参数 TransactionOption falsePass null for the transaction parameter when the TransactionOption property is false. 如果 TransactionOption 属性为 true ,则可以传入 null transaction 参数以指示容器支持事务,但不参与。If the TransactionOption property is true, you can pass null in the transaction parameter to indicate that the container supports transactions but does not participate.

Applies to