VB.net 2008 Oracle 在事务内更新仅提交部分
VB.net 2008 Oracle update within a transaction only commiting part
我们遇到了一个棘手的问题,我们有 vb.net 应用程序正在通过 select 对 oracle 的查询获取可更新数据 reader。我们使用 ODBC 进行连接。
我们有两个 tables F4201 和 f4211,01 table 是 header,11 是细节。
我们在交易中对两个 table 进行了更新,但我们发现在某些看似随机的情况下,只有详细信息得到更新,而 header 没有。例如,请参见下面的代码。
Dim cnnE1 As OdbcConnection
Dim txn As OdbcTransaction
Dim E1Database As String = My.Settings.SettingValue("E1Database")
Try
cnnE1 = DbConn.CreateConnection(My.Settings.E1Conn)
cnnE1.Open()
Catch ex As Exception
Return ProcessReturnType.Fail
End Try
txn = cnnE1.BeginTransaction
ssql = "SELECT * FROM " & E1Database & ".F4201 WHERE SHDOCO = " & tmpTrafficOrder
If Not DbConn.GetUpdateableDataAdapter(ssql, cnnE1, daSales_Header, txn) Then
txn.Rollback()
Dispose_ODBC_Connection(cnnE1)
Return ProcessReturnType.Fail
End If
If daSales_Header.Fill(dsSales_Header) > 0 Then
'If Sales Order Header has matching records then grab the Sales Order Detail records as well
'ssql = "SELECT * FROM " & E1Database & ".F4211 WHERE LTRIM(SDKCOO) = '" & tmpDemandLocation & "' AND SDDOCO = " & tmpTrafficOrder
ssql = "SELECT * FROM " & E1Database & ".F4211 WHERE SDDOCO = " & tmpTrafficOrder
If Not DbConn.GetUpdateableDataAdapter(ssql, cnnE1, daSales_Detail, txn) Then
txn.Rollback()
Dispose_ODBC_DataAdapter(daSales_Header)
Dispose_ODBC_Connection(cnnE1)
Return ProcessReturnType.Fail
End If
end if
'This function uses sql to map XML elements from the file we receive to the Oracle Field and updated the DR with the information.
'Testing shows the DR is updated with the new values after this runs
If Not oMapping.MapObjectToDataRow(fileId, ApptNotification, drSales_Header, "ApptNotif.SalesHeader", mapSubSet, My.Settings.InterfaceType) Then
txn.Rollback()
Dispose_ODBC_DataAdapter(daSales_Header)
Dispose_ODBC_Connection(cnnE1)
Return ProcessReturnType.Fail
End If
daSales_Header.Update(dsSales_Header)
dsSales_Header.AcceptChanges()
'Now time for details.
If daSales_Detail.Fill(dsSales_Detail) > 0 Then
For Each drSales_Detail As DataRow In dsSales_Detail.Tables(0).Rows
If Not oMapping.MapObjectToDataRow(fileId, ApptNotification, drSales_Detail, "ApptNotif.SalesDetail", mapSubSet, My.Settings.InterfaceType) Then
txn.Rollback()
Dispose_ODBC_DataAdapter(daSales_Header)
Dispose_ODBC_DataAdapter(daSales_Detail)
Dispose_ODBC_Connection(cnnE1)
Return ProcessReturnType.Fail
End If
daSales_Detail.Update(dsSales_Detail)
dsSales_Detail.AcceptChanges()
next
Else
txn.Rollback()
Dispose_ODBC_Connection(cnnE1)
Return ProcessReturnType.Skip
End If
txn.Commit()
txn.Dispose()
cnnE1.Close()
cnnE1.Dispose()
经过进一步调查,我们发现不是事务有问题,它正在正确更新 table,有一个单独的进程 运行 正在将值改回。
我们遇到了一个棘手的问题,我们有 vb.net 应用程序正在通过 select 对 oracle 的查询获取可更新数据 reader。我们使用 ODBC 进行连接。
我们有两个 tables F4201 和 f4211,01 table 是 header,11 是细节。
我们在交易中对两个 table 进行了更新,但我们发现在某些看似随机的情况下,只有详细信息得到更新,而 header 没有。例如,请参见下面的代码。
Dim cnnE1 As OdbcConnection
Dim txn As OdbcTransaction
Dim E1Database As String = My.Settings.SettingValue("E1Database")
Try
cnnE1 = DbConn.CreateConnection(My.Settings.E1Conn)
cnnE1.Open()
Catch ex As Exception
Return ProcessReturnType.Fail
End Try
txn = cnnE1.BeginTransaction
ssql = "SELECT * FROM " & E1Database & ".F4201 WHERE SHDOCO = " & tmpTrafficOrder
If Not DbConn.GetUpdateableDataAdapter(ssql, cnnE1, daSales_Header, txn) Then
txn.Rollback()
Dispose_ODBC_Connection(cnnE1)
Return ProcessReturnType.Fail
End If
If daSales_Header.Fill(dsSales_Header) > 0 Then
'If Sales Order Header has matching records then grab the Sales Order Detail records as well
'ssql = "SELECT * FROM " & E1Database & ".F4211 WHERE LTRIM(SDKCOO) = '" & tmpDemandLocation & "' AND SDDOCO = " & tmpTrafficOrder
ssql = "SELECT * FROM " & E1Database & ".F4211 WHERE SDDOCO = " & tmpTrafficOrder
If Not DbConn.GetUpdateableDataAdapter(ssql, cnnE1, daSales_Detail, txn) Then
txn.Rollback()
Dispose_ODBC_DataAdapter(daSales_Header)
Dispose_ODBC_Connection(cnnE1)
Return ProcessReturnType.Fail
End If
end if
'This function uses sql to map XML elements from the file we receive to the Oracle Field and updated the DR with the information.
'Testing shows the DR is updated with the new values after this runs
If Not oMapping.MapObjectToDataRow(fileId, ApptNotification, drSales_Header, "ApptNotif.SalesHeader", mapSubSet, My.Settings.InterfaceType) Then
txn.Rollback()
Dispose_ODBC_DataAdapter(daSales_Header)
Dispose_ODBC_Connection(cnnE1)
Return ProcessReturnType.Fail
End If
daSales_Header.Update(dsSales_Header)
dsSales_Header.AcceptChanges()
'Now time for details.
If daSales_Detail.Fill(dsSales_Detail) > 0 Then
For Each drSales_Detail As DataRow In dsSales_Detail.Tables(0).Rows
If Not oMapping.MapObjectToDataRow(fileId, ApptNotification, drSales_Detail, "ApptNotif.SalesDetail", mapSubSet, My.Settings.InterfaceType) Then
txn.Rollback()
Dispose_ODBC_DataAdapter(daSales_Header)
Dispose_ODBC_DataAdapter(daSales_Detail)
Dispose_ODBC_Connection(cnnE1)
Return ProcessReturnType.Fail
End If
daSales_Detail.Update(dsSales_Detail)
dsSales_Detail.AcceptChanges()
next
Else
txn.Rollback()
Dispose_ODBC_Connection(cnnE1)
Return ProcessReturnType.Skip
End If
txn.Commit()
txn.Dispose()
cnnE1.Close()
cnnE1.Dispose()
经过进一步调查,我们发现不是事务有问题,它正在正确更新 table,有一个单独的进程 运行 正在将值改回。