From 23a65cdeefc028fe3cbee53b5a7db3bc3314a66e Mon Sep 17 00:00:00 2001 From: Jonathan Jenne Date: Mon, 10 May 2021 16:11:38 +0200 Subject: [PATCH] Jobs/ZUGFeRD: Fix transactions not committed when expected errors happen (md5, etc.) --- Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb b/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb index 2f1052c8..53391606 100644 --- a/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb +++ b/Modules.Jobs/EDMI/ZUGFeRD/ImportZUGFeRDFiles.vb @@ -177,6 +177,10 @@ Public Class ImportZUGFeRDFiles ' Will be set only at the end of the function if no error occurred. Dim oIsSuccess As Boolean = False + ' Flag to save if the occurred error (if any) was expected + ' Used to determine if transactions should be committed or not + Dim oExpectedError As Boolean = True + ' Create file lists Dim oFileGroupFiles As List(Of FileInfo) = oFileGroup.Value Dim oEmailAttachmentFiles As New List(Of FileInfo) @@ -433,6 +437,8 @@ Public Class ImportZUGFeRDFiles oMoveDirectory = DIRECTORY_DONT_MOVE + oExpectedError = False + Catch ex As Exception _logger.Warn("Unknown Error occurred: {0}", ex.Message) _logger.Error(ex) @@ -453,6 +459,8 @@ Public Class ImportZUGFeRDFiles oMoveDirectory = DIRECTORY_DONT_MOVE + oExpectedError = False + Finally Try ' If an application error occurred, dont move files so they will be processed again later @@ -480,9 +488,10 @@ Public Class ImportZUGFeRDFiles End Try Try - ' If everything went OK, finally commit all changes to the Database + ' If everything went OK or an expected error occurred, + ' finally commit all changes To the Database ' ================================================================== - If oIsSuccess Then + If oIsSuccess Or oExpectedError Then ' Commit SQL Transaction oSQLTransaction.Commit()