From 5a9a30d6f1534ed28abbf55f225434481bc8372a Mon Sep 17 00:00:00 2001 From: pitzm Date: Fri, 28 Jun 2024 11:40:12 +0200 Subject: [PATCH] Modules.Jobs: Manchmal geht die DB-Connection verloren. Dann darf aber die Datei auch nicht verschoben werden, die gerade bearbeitet wurde. --- Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb | 35 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb index d4f24de7..4525c82a 100644 --- a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb +++ b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb @@ -370,21 +370,22 @@ Public Class ImportZUGFeRDFiles _logger.Warn("Unknown Error occurred: {0}", ex.Message) _logger.Error(ex) - ' Send Email to Digital Data - Dim oBody = _email.CreateBodyForUnhandledException(oMessageId, ex) - Dim oEmailData As New EmailData With { - .From = oArgs.ExceptionEmailAddress, - .Subject = $"UnhandledException im ZUGFeRD-Parser @ {oMessageId}" - } - _email.AddToEmailQueueMSSQL(oMessageId, oSQLTransaction, oBody, oEmailData, "UnhandledException", _EmailOutAccountId, oArgs.NamePortal, oArgs.RejectionTemplateId, ErrorCode.UnhandledException, ex.Message, ex.StackTrace) - - ' Rollback Transaction - oSQLTransaction.Rollback() - oMoveDirectory = DIRECTORY_DONT_MOVE - oExpectedError = False + If oSQLConnection IsNot Nothing And oSQLTransaction IsNot Nothing Then + ' Send Email to Digital Data + Dim oBody = _email.CreateBodyForUnhandledException(oMessageId, ex) + Dim oEmailData As New EmailData With { + .From = oArgs.ExceptionEmailAddress, + .Subject = $"UnhandledException im ZUGFeRD-Parser @ {oMessageId}" + } + _email.AddToEmailQueueMSSQL(oMessageId, oSQLTransaction, oBody, oEmailData, "UnhandledException", _EmailOutAccountId, oArgs.NamePortal, oArgs.RejectionTemplateId, ErrorCode.UnhandledException, ex.Message, ex.StackTrace) + + ' Rollback Transaction + oSQLTransaction.Rollback() + End If + Finally Try ' If an application error occurred, dont move files so they will be processed again later @@ -414,8 +415,10 @@ Public Class ImportZUGFeRDFiles ' finally commit all changes To the Database ' ================================================================== If oIsSuccess Or oExpectedError Then - ' Commit Transaction - oSQLTransaction.Commit() + If oSQLTransaction IsNot Nothing Then + ' Commit Transaction + oSQLTransaction.Commit() + End If End If Catch ex As Exception _logger.Error(ex) @@ -423,7 +426,9 @@ Public Class ImportZUGFeRDFiles End Try Try - oSQLConnection.Close() + If oSQLConnection IsNot Nothing Then + oSQLConnection.Close() + End If Catch ex As Exception _logger.Error(ex) _logger.Warn("Database Connections were not closed successfully.")