2014-02-11 39 views
0

我正在以編程方式在for循環中創建executableql任務並將其添加到我的包中。現在,Add調用返回給我一個Executable集合對象。我想根據我添加的任務的某些唯一性將這些引用存儲在帶有一些字符串鍵名的字典中。存儲可執行文件/任務主機的引用以添加優先級約束

我想要這樣做,以便在完成for循環時,可以在所有任務完成後在各種可執行任務之間添加優先約束。有沒有辦法做到這一點?

我試着創建一個字符串字典到可執行文件,但是當從Add方法添加返回的可執行文件時,我可以得到Executable爲NULL的異常。 MSDN這裏舉了一個例子如何添加這樣

using System; 
using Microsoft.SqlServer.Dts.Runtime; 

namespace Microsoft.SqlServer.Dts.Samples 
{ 
    class Program 
    { 
    static void Main(string[] args) 
    { 
     Package p = new Package(); 

     // Add a File System task. 
     Executable eFileTask1 = p.Executables.Add("STOCK:FileSystemTask"); 
     TaskHost thFileHost1 = eFileTask1 as TaskHost; 

     // Add a second File System task. 
     Executable eFileTask2 = p.Executables.Add("STOCK:FileSystemTask"); 
     TaskHost thFileHost2 = eFileTask2 as TaskHost; 

     // Put a precedence constraint between the tasks. 
     // Set the constraint to specify that the second File System task cannot run 
     // until the first File System task finishes. 
     PrecedenceConstraint pcFileTasks = 
     p.PrecedenceConstraints.Add((Executable)thFileHost1, (Executable)thFileHost2); 
     pcFileTasks.Value = DTSExecResult.Completion; 
    } 
    } 
} 

先後約束我的方案,它只是被添加任務的數量是動態控制的,我想存儲創建這樣以後每個任務手柄我可以將這些句柄傳遞給添加優先級約束func調用。

回答

0

我能得到它的工作。它以正常的預期方式工作。

0

你連接錯誤的東西。添加將要期待Executable,而不是TaskHost

PrecedenceConstraint pcFileTasks = p.PrecedenceConstraints.Add(eFileTask1, eFileTask2); 

使用此代碼,我產生了以下包裏面有兩個任務之間的Completion優先約束。

enter image description here

+0

taskhost也可以在可執行文件中傳遞。上述代碼取自MSDN網站。 http://technet.microsoft.com/en-us/library/ms135956.aspx我的問題不是關於taskhosts和Executable之間的區別,而是如何保留對集合對象中的可執行文件的引用,以便稍後可以使用它。 – bootkick

+0

然後編輯你的問題,並提供*代碼 – billinkc

+0

這是代碼。 – bootkick