Exception Handling in SSIS Script Task

In SSIS Script Task you can use the same Structured Exception Handling (SEH) as in normal VB.NET or C# code.

Using this Structured Exception Handling you can catch specific errors as they occur and perform any appropriate action needed like letting the user know about what kind of error occurred, or logging the error or to perform some specific plan of action depending on the error.

In SSIS Script task you can Return Failure Status whenever an error is caught.

Here is an example of exception handling in Visual Basic.NET.

Public Sub Main()
Dim fileContent As String
Catch ex As System.IO.FileNotFoundException
Dts.TaskResult = Dts.Results.Failure
End Try
Dts.TaskResult = Dts.Results.Success
End Sub

Above code tries to read the content of the file C:\file.txt and it will fail if file does not exist and throw an exception of type System.IO.FileNotFoundException. This exception will be caught in the catch block where we are returning the TaskResult as Failure. Additionally, you can perform any other action you want in this catch block.

No comments:


Powered by Blogger.