The Script Task in SQL Server 2005 SSIS creates a default script that looks like this:
Public Sub Main()
'
' Add your code here
'
Dts.TaskResult = Dts.Results.Success
End Sub
I contend that this is backwards. The code template puts the setting of the Dts.TaskResult at the *end* of the function, with the "Add your code here" instruction *above* it. The tendency will be, as the instruction in the comment seems to indicate, that setting the task result should be the last thing you do.
I say it should be like this:
Public Sub Main()
'Assume success
Dts.TaskResult = Dts.Results.Success
'
' Add your code here.
'
End Sub
That way, if someone figures out in the logic of their script that they need to fail the task, that "Success" line is not sitting there at the end of the function to reverse that. It's a minor point, perhaps, but it's a trap I fell into when developing one of my first script tasks: I failed a task in the body of the code, but it kept succeeding anyway. Then I realized that line was still sitting there at the end. With the success line at the top, it all works out fine, as in this example:
Public Sub Main()
'Assume success
Dts.TaskResult = Dts.Results.Success
Try
'Imagine here a call to something
'that could throw an exception
Throw New System.Exception("Forced error for testing.")
Catch ex As System.Exception
Dts.Events.FireError(-1, "N/A", ex.ToString(), "", 0)
Dts.TaskResult = Dts.Results.Failure
End Try
End Sub
Thoughts welcome. Am I missing something?
Dan