提问人:bendataclear 提问时间:6/13/2023 最后编辑:bendataclear 更新时间:6/19/2023 访问量:163
MS Access 正在将更新复制到链接表
MS Access is duplicating updates to a linked table
问:
我有一个连接到 Azure SQL Server 数据库的 MS-Access 前端。
我看到数据库的一些非常奇怪的更新,我已将其追溯到通过 运行合并查询的合并查询,运行合并的代码如下:ADODB.Command
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
表 和 都是链接表。TblQuantities
TblTrnLines
此查询正在正确地进行更新,但很少,更新似乎以看似随机的间隔重复 1 次或多次。
向表添加触发器以记录更新向我显示如下内容:
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
这似乎发生在大约 1% 的调整中,没有时间间隔(在本例中为 76、58、12 秒,然后是 24 秒)。所有更新均由同一用户进行,连接中使用相同的 APP。中的差距来自我为了可读性而减少了 s 的数量。完整数据具有完全连续的 s。Audit ID
Product ID
Audit ID
以前有没有人见过这种情况,或者有没有人知道为什么会发生这种情况以及如何预防它?
编辑:连接字符串为 。ODBC;DRIVER=ODBC Driver 13 for SQL Server;SERVER=[servername].database.windows.net;DATABASE=[dbname];UID=[userid];PWD=[userpassword]
答: 暂无答案
评论