次の方法で共有


Package.Execute メソッド

パッケージの実行が成功したかどうかの情報を含む DTSExecResult 列挙を返します。

名前空間:  Microsoft.SqlServer.Dts.Runtime
アセンブリ:  Microsoft.SqlServer.ManagedDTS (Microsoft.SqlServer.ManagedDTS.dll)

構文

'宣言
Public Function Execute As DTSExecResult
'使用
Dim instance As Package 
Dim returnValue As DTSExecResult 

returnValue = instance.Execute()
public DTSExecResult Execute()
public:
DTSExecResult Execute()
member Execute : unit -> DTSExecResult
public function Execute() : DTSExecResult

戻り値

型: Microsoft.SqlServer.Dts.Runtime.DTSExecResult
パッケージの実行が成功したかどうかの情報を含む DTSExecResult 列挙です。

説明

Execute メソッドは、DtsContainer クラスを通じてタスク ホストおよび Executable 抽象クラスのその他のオブジェクトにより継承され、継承オブジェクトのランタイム エンジンによる実行を許可します。 個々のオブジェクトによって継承された Execute メソッドは通常、コードで使用されません。パッケージでタスクまたはコンテナーのいずれかを実行する必要がある場合は、Execute メソッドを呼び出すことをお勧めします。 ただし、このメソッドを必要とする特定の状況においては、個々のオブジェクトで Execute メソッドを使用できます。

Execute メソッドは主に、カスタム タスクを作成するときに継承およびオーバーライドするために使用されます。 Execute メソッドをオーバーライドする方法の詳細については、「カスタム タスクのコーディング」を参照してください。

Execute メソッドは、パッケージの実行前に暗黙的に Validate メソッドを呼び出します。 検証中、パッケージ内のすべてのタスクが適切な設定になっているかが確認され、パッケージ、コンテナー、およびパッケージ内のその他のコンポーネントを含め、パッケージ内のすべてのオブジェクトが検証されます。

検証フェーズにパッケージが失敗する原因となるような問題が存在しない場合、パッケージ オブジェクトはパッケージ内の各タスクとオブジェクトごとに Execute メソッドを呼び出します。

TransactionOption プロパティが false である場合、transaction パラメーターには nullNULL 参照 (Visual Basic では Nothing) を渡します。 TransactionOption プロパティが true の場合は、transaction パラメーターに nullNULL 参照 (Visual Basic では Nothing) を渡して、コンテナーがトランザクションをサポートしているが参加していないことを示すことができます。

使用例

次のコード例では、パッケージを作成し、スクリプト タスクを追加する前に、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

関連項目

参照

Package クラス

Execute オーバーロード

Microsoft.SqlServer.Dts.Runtime 名前空間