Tuesday, September 2, 2008

Raising errors in the history

/*
I have been looking into raising customer errors in a large collection of file copy routines I am creating to provide better logging for a collection of PDFs we use for various websites. This is a start of what I am looking for and will be added to as I find new features.

The error will be posted in the SSIS history so it will be easier to find when doing the morning audit.

*/

Dim filename As String = Dts.Variables("PDF_filename").Value.ToString
Dim sourceFilePath As String = Dts.Variables("SourceFilePath").Value.ToString
Dim destFilePath As String = Dts.Variables("DestinationFilePath").Value.ToString
Dim destFilePathArchive As String = Dts.Variables("DestinationFilePathArchive").Value.ToString
Dim purgeSourceFile As String = CBool(Dts.Variables("PurgeSourceFile").Value.ToString)
Dim ArchiveFilePath As String = Dts.Variables("archivePathExtension").Value.ToString

Dim sourceFileName As String = sourceFilePath & "\" & filename
Dim destFileName As String = destFilePath & "\" & filename
Dim destFileNameArchive As String = destFilePathArchive & "\" & filename

Dim CopyDest As String = destFilePath & ArchiveFilePath & "\" & filename

Try
File.SetAttributes(destFileName, FileAttributes.Normal)
'Make sure that if the file exists at the destination it is not read only
If File.Exists(CopyDest) Then
File.SetAttributes(CopyDest, FileAttributes.Normal)
End If
File.Copy(destFileName, CopyDest, True)
File.SetLastWriteTime(CopyDest, Now())
File.Copy(sourceFileName, destFileName, True)
Catch ex As Exception
'An error occurred.
Dts.Events.FireError(0, "Error in file copy", _
ex.Message & ControlChars.CrLf & ex.StackTrace, _
String.Empty, 0)
Dts.TaskResult = Dts.Results.Failure
End Try

No comments: