Try Catch within an SSIS Script Tasks and Components

Using aTry/Catch/Finally within yourScript ComponentsandScript Tasksis just good coding practice. The thing you want to be able to do is push any errors you trap to a log file. The syntax is somewhat simple, but it took me some time to research it and it differs depending upon whether it's aComponent orTask. I'll go over each.

Within theComponent there is no access to theDts object, so you need to work through theComponentMetaData object as shown below. Please note thepbCancel is defined as abool at the top of myComponent.

The tricky part is using theComponentMetaData to access the log. TheComponentwill fail if any of theTry block fails, regardless of thepbCancelvalue. This is primarily to interact with the log, like a good programmer :)

Within theTask you access the log from the same object you access just about anything, Dts. To access the log you simply useDts.Log and you can fail theTaskby simply setting the Dts.TaskResult=Dts.Results.Failure.