Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Execute Method
Collapse the table of content
Expand the table of content

ExecuteSQLTask.Execute Method

Runs the task.

Namespace:  Microsoft.SqlServer.Dts.Tasks.ExecuteSQLTask
Assembly:  Microsoft.SqlServer.SQLTask (in Microsoft.SqlServer.SQLTask.dll)

public override DTSExecResult Execute(
	Connections connections,
	VariableDispenser variableDispenser,
	IDTSComponentEvents events,
	IDTSLogging log,
	Object transaction


Type: Microsoft.SqlServer.Dts.Runtime.Connections
A Connections collection for the task.
Type: Microsoft.SqlServer.Dts.Runtime.VariableDispenser
A Variables collection for the task.
Type: Microsoft.SqlServer.Dts.Runtime.IDTSComponentEvents
An IDTSComponentEvents interface to raise events.
Type: Microsoft.SqlServer.Dts.Runtime.IDTSLogging
An IDTSLogging interface.
Type: System.Object
The transaction object that the task is part of. This value can be null.

Return Value

Type: Microsoft.SqlServer.Dts.Runtime.DTSExecResult
A value from the DTSExecResult enumeration.

The Execute method is inherited by task hosts and other objects from the Executable abstract class, through the DtsContainer class, and allows the inheriting objects to be run by the runtime engine. The Execute method inherited by the individual objects is not commonly used in code, and it is recommended that you call the Execute method if you need to run any of the tasks or containers in the package. However, the Execute method is available on individual objects should you find a unique circumstance where it is needed.

The main use of the Execute method is for it to be inherited and overridden when you create a custom task. For more information about how to override the Execute method, see Coding a Custom Task.

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.

If there are no problems encountered in the validation phase that would cause the package to fail, the package object proceeds to call the Execute method for each task and object in the package.

Pass null for the transaction parameter when the TransactionOption property is false. 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.

The following code example shows how to run a package containing a BulkInsertTask after some of the task properties are set. The Bulk Insert task is an example for this code sample; any task can be created in its place.

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.

            // Review the results of package execution.
            if (taskH.ExecutionResult == DTSExecResult.Failure || taskH.ExecutionStatus == DTSExecStatus.Abend)
                Console.WriteLine("Task failed or abended");
                Console.WriteLine("Task ran successfully");

Community Additions

© 2015 Microsoft