2012-11-22 136 views
3

失敗,我們需要SSIS腳本任務失敗在一定條件下SSIS腳本任務不DTS.TaskResult

If var_status = "Y" 
Msgbox("Error Found") 
Dts.TaskResult = ScriptResults.Failure 
End If 

但是,當我們運行它會在IF條件,但沒有失敗的腳本任務。

任何人都可以請建議

+0

上面粘貼的代碼中沒有循環。你能粘貼整個代碼嗎?此外,當故障條件得到滿足時,如果在** If **條件中使用** Return **,則不會返回,因爲這會破壞(不可見)循環。 – user1826905

+0

道歉 - 當我說我看我的意思是它在IF條件下,但不會使任務失敗。 –

+0

我已經更新了代碼。 Msgbox確實得到執行,但任務不會失敗。 –

回答

2
If var_status = "Y" 
    Msgbox("Error Found") 
    Dts.TaskResult = ScriptResults.Failure 
    Return 
End If 

假設** ScriptResults.Failure相同Dts.Results.Failure

0

您可以使用此技術:

嘗試 {

//Code goes here that may throw exception or succeed 
    Dts.TaskResult = (int)ScriptResults.Success; 

} 
catch (Exception e) 
{ 

    //Outputs a message to the Output window of SSDT/BIDS 
    Dts.Events.FireError(-1, "My Task Name", e.message, String.Empty, 0); 

    // Makes a package fail (or intercept in Event Handler) 
    Dts.TaskResult = (int)ScriptResults.Failure; 

}