Error Handling in script Task SSIS Using Try Catch
Hi All,
I am using try-catch block inside a script task for capturing an error, So that could Load into DB error_log Table. For this I am using a package level variable. I also redirect the error to DB using an Execute SQL Task by writing Insert Statement and declaring
the variable which I used in the script task. Once the Script task is failed then the error is logging successfully into the DB until Now. Everything is fine here, But when the error is logging I see three records inserted into the Error Table. Could Some
Body Give me an idea.
The code goes here: I have gave all the connections correct and declared all the variable required, just help me if this code is correct or not.
Try
Dim ifilepathandname As String =
Dts.Variables("Var1").Value.ToString + "\" +
Dts.Variables("Var1").Value.ToString + Dts.Variables("Var3").Value.ToString
Dts.Connections("File_Conn").CONNECTIONSTRING = 1FILEPATHANDNAME
Dts.Connections("OupFile_Conn").CONNECTIONSTRING = 1FILEPATHANDNAME
Catch ex As Exception
Dts.Variables("va").Value = ex.Message.ToString()
Dts.TaskResult = Dts.Results.Failure
End Try
End Sub
---------------------------------------------------------------------------
Here in the code below I could not Log the error if the script fails, Could some body suggest. After script it should go to SQl task at Failure and log the error.
Public Sub Main()
Try
Dim Rowcount As Integer Rowcount
= CInt(Dts.Variables("Rowcount").Value)
If File.Exists("C:\My
Docs\Progs\File.txt") Then
Dim tw As TextWriter
= New StreamWriter("C:\My
Docs\Progs\File.txt", True)
tw.WriteLine(Rowcount &", no of rows in the file ")
tw.Close()
End If
Catch ex As Exception
Dts.Variables("va2").Value = ex.Message.ToString
End Try
Dts.TaskResult = Dts.Results.Success
End Sub
Thanks in advance to all..
Cheers
March 14th, 2011 9:02pm