I have an MS-Access front end connected to an Azure SQL Server database.
I am seeing some very strange updates to the database which I have traced to a merge query being run via an ADODB.Command, the code that runs the merge is below:
Dim cmd As ADODB.Command
   
Set cmd = New ADODB.Command
Dim svr As String
Dim db As String
Dim drv As String
Dim con As ConnectionData
Dim QueryText As String
Dim TransactionID As Integer
TransactionID = Eval("Forms![FrmTransactions]![ID]")
QueryText = "MERGE TblQuantities t" & vbCrLf & _
           "USING (SELECT TblTrnLines.ProductID, TblTrnLines.[Type], Sum(TblTrnLines.Quantity) AS SumOfQuantity" & vbCrLf & _
           "FROM TblTrnLines" & vbCrLf & _
           "WHERE (((TblTrnLines.Deleted) = 0) And ((TblTrnLines.StockTransID) = " & TransactionID & "))" & vbCrLf & _
           "GROUP BY TblTrnLines.ProductID, TblTrnLines.[Type]) s" & vbCrLf & _
           "ON (s.ProductID = t.ProductID) and (s.[type] = t.StockTypeID) and (1 = t.StockLocationID)" & vbCrLf & _
           "WHEN MATCHED" & vbCrLf & _
           "THEN UPDATE set" & vbCrLf & _
           "t.Quantity = (t.Quantity + s.SumOfQuantity)" & vbCrLf & _
           "WHEN Not MATCHED" & vbCrLf & _
           "THEN INSERT (ProductID, StockTypeID, StockLocationID, Quantity)" & vbCrLf & _
           "VALUES (s.ProductID, s.[type], 1, s.SumOfQuantity);"
With cmd
  .ActiveConnection = "[connection_string]"
  .CommandType = adCmdText
  .CommandText = QueryText
  .Execute
The tables TblQuantities and TblTrnLines are both linked tables.
This query is making the updates correctly, however very rarely, the updates seems to get repeated at seemingly random intervals 1 or more times.
Adding a trigger to the table to record updates shows me something like this:
Audit ID   Datetime                    ProductID   AdjustedQty
6305       2023-06-06 16:07:26.330           411            10
6306       2023-06-06 16:07:26.330           185             3
6312       2023-06-06 16:07:26.330             8            10
6313       2023-06-06 16:08:42.390           411            10
6314       2023-06-06 16:08:42.390           185             3
6320       2023-06-06 16:08:42.390             8            10
6321       2023-06-06 16:09:39.940           411            10
6322       2023-06-06 16:09:39.940           185             3
6328       2023-06-06 16:09:39.940             8            10
6329       2023-06-06 16:09:52.387           411            10
6330       2023-06-06 16:09:52.387           185             3
6336       2023-06-06 16:09:52.387             8            10
6337       2023-06-06 16:10:16.280           411            10
6338       2023-06-06 16:10:16.280           185             3
6344       2023-06-06 16:10:16.280             8            10
This seems to happen for about 1% of adjustments, with no pattern to the time between (in this case, 76, 58, 12 then 24 seconds). All the updates are made by the same user, with the same APP in the connection. The gaps in the Audit ID are from me reducing the number of Product IDs for readability. The full data has completely contiguous Audit IDs.
Has anyone seen this before or does anyone have any idea why this is happening and how to prevent it?
Edit: The connection string is ODBC;DRIVER=ODBC Driver 13 for SQL Server;SERVER=[servername].database.windows.net;DATABASE=[dbname];UID=[userid];PWD=[userpassword].
