From bb7ed1bdd8f1f06a5363a3164991b5fe9e278c79 Mon Sep 17 00:00:00 2001 From: pitzm Date: Tue, 14 Jan 2025 13:51:06 +0100 Subject: [PATCH] =?UTF-8?q?Zugferd/Jobs:=20Falls=20DB-Fehler=20beim=20L?= =?UTF-8?q?=C3=B6schen=20passiert,=20wird=20jetzt=20darauf=20reagiert.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb | 54 +++++------------------------- 1 file changed, 9 insertions(+), 45 deletions(-) diff --git a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb index 52dd8522..9c74d35f 100644 --- a/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb +++ b/Jobs/ZUGFeRD/ImportZUGFeRDFiles.vb @@ -548,25 +548,9 @@ Public Class ImportZUGFeRDFiles End If - DeleteExistingPropertyValues(pMessageId, oConnections) - - ' MP 05.06.2024 - Einzel-Inserts durch BULK-Insert abgelöst - 'Dim oFirstProperty = oCheckResult.ValidProperties.FirstOrDefault() - 'If oFirstProperty IsNot Nothing Then - ' InsertPropertyValue(pMessageId, oConnections, New PropertyValues.ValidProperty() With { - ' .MessageId = pMessageId, - ' .Description = "ZUGFeRDSpezifikation", - ' .GroupCounter = 0, - ' .IsRequired = False, - ' .Value = oDocument.Specification, - ' .TableName = oFirstProperty.TableName, - ' .TableColumn = "ZUGFERD_SPECIFICATION" - ' }) - 'End If - - 'For Each oProperty In oCheckResult.ValidProperties - ' InsertPropertyValue(pMessageId, oConnections, oProperty) - 'Next + If DeleteExistingPropertyValues(pMessageId, oConnections) = False Then + Throw New Exception("Could not cleanup data. Exiting.") + End If ' DataTable vorbereiten Dim oDataTable As DataTable = FillDataTable(pMessageId, oCheckResult, oDocument.Specification, oDocument.UsedXMLSchema) @@ -585,6 +569,7 @@ Public Class ImportZUGFeRDFiles If oBulkResult = False Then _logger.Error("Bulk Insert for MessageId [{0}] failed!", pMessageId) + Throw New Exception("Bulk Insert failed! Exiting.") End If _logger.Info("Bulk Insert finished. [{0}] rows inserted for MessageId [{1}].", oDataTable.Rows.Count, pMessageId) @@ -661,38 +646,17 @@ Public Class ImportZUGFeRDFiles Return oDataTable End Function - Private Sub DeleteExistingPropertyValues(pMessageId As String, pConnections As DatabaseConnections) + Private Function DeleteExistingPropertyValues(pMessageId As String, pConnections As DatabaseConnections) As Boolean Dim oDelSQL = $"DELETE FROM TBEDMI_ITEM_VALUE where REFERENCE_GUID = '{pMessageId}'" - Dim oStep As String + Dim oStep As String = "TBEDMI_ITEM_VALUE Delete MessageID Items" - oStep = "TBEDMI_ITEM_VALUE Delete MessageID Items" Try - _mssql.ExecuteNonQueryWithConnectionObject(oDelSQL, pConnections.SQLServerConnection, MSSQLServer.TransactionMode.ExternalTransaction, pConnections.SQLServerTransaction) + Dim retValue As Boolean = _mssql.ExecuteNonQueryWithConnectionObject(oDelSQL, pConnections.SQLServerConnection, MSSQLServer.TransactionMode.ExternalTransaction, pConnections.SQLServerTransaction) + Return retValue Catch ex As Exception _logger.Warn("Step [{0}] with SQL [{1}] was not successful.", oStep, oDelSQL) End Try - End Sub - - ' Alte Insert-Methode - 'Private Sub InsertPropertyValue(pMessageId As String, pConnections As DatabaseConnections, pProperty As PropertyValues.ValidProperty) - ' Dim oGroupCounterValue = pProperty.GroupCounter - - ' ' If GroupCounter is -1, it means this is a default property that can only occur once. - ' ' Set the actual inserted value to 0 - ' If oGroupCounterValue = -1 Then - ' oGroupCounterValue = 0 - ' End If - - ' Dim oCommand = $"INSERT INTO {pProperty.TableName} (REFERENCE_GUID, ITEM_DESCRIPTION, ITEM_VALUE, GROUP_COUNTER, SPEC_NAME, IS_REQUIRED) VALUES - ' ('{pMessageId}', '{pProperty.Description}', '{pProperty.Value.Replace("'", "''")}', {oGroupCounterValue},'{pProperty.TableColumn}','{pProperty.IsRequired}')" - ' _logger.Debug("Mapping Property [{0}] with value [{1}], Will be inserted into table [{2}]", pProperty.TableColumn, pProperty.Value.Replace("'", "''"), pProperty.TableName) - - ' ' Insert into SQL Server - ' Dim oResult = _mssql.ExecuteNonQueryWithConnectionObject(oCommand, pConnections.SQLServerConnection, MSSQLServer.TransactionMode.ExternalTransaction, pConnections.SQLServerTransaction) - ' If oResult = False Then - ' _logger.Warn($"SQL Command [{oCommand}] was not successful. Check the log.") - ' End If - 'End Sub + End Function Private Function BulkInsert(pConnections As DatabaseConnections, pTable As DataTable, pDestinationTable As String, pColumns As List(Of String)) As Boolean