我在下面有一部分函数,它从第一个 SProc 中检索 autoID 并将其作为参数传递给另一个 SProc。在这里我使用事务回滚,假设我有一个场景,第一个 SProc 成功执行了所有操作,但在第二个 SProc 中遇到问题,第一个 SProc 操作是否会与第二个 SProc 一起回滚?一直以来,我只需要处理一个 SProc 事务,但这对我来说有点不同。谢谢。
Public Shared Function VoucherRedemption(ByVal dbTrans As DbTransaction _
, ByVal dbConnection As DbConnection _
, ByVal receiptNo As String _
, ByVal voucherNo As String _
, ByVal customerCode As String) As Boolean
Dim dbCommand As DbCommand = Nothing
Try
If DbConnection.State <> ConnectionState.Open Then
DbConnection.Open()
End If
dbCommand = GetStoredProcedureCommand("Mem_Redeem")
dbCommand.Connection = DbConnection
dbCommand.Transaction = dbTrans
AddInParameter(dbCommand, "@ReceiptNo", DbType.String, 50, DBNull.Value)
If Not String.IsNullOrEmpty(receiptNo) Then
dbCommand.Parameters("@ReceiptNo").Value = receiptNo
End If
AddOutParameter(dbCommand, "@OutAutoIDs", DbType.String, 4000, DBNull.Value)
ExecuteNonQuery(dbCommand)
Dim outAutoIDs As String = CType(dbCommand.Parameters("@OutAutoIDs").Value, String)
dbCommand = GetStoredProcedureCommand("Mem_Redeem_Log_Add")
dbCommand.Connection = DbConnection
dbCommand.Transaction = dbTrans
AddInParameter(dbCommand, "@VoucherNo", DbType.String, 50, DBNull.Value)
dbCommand.Parameters("@VoucherNo").Value = voucherNo
AddInParameter(dbCommand, "@RedeemTransactAutoID", DbType.String, 4000, DBNull.Value)
dbCommand.Parameters("@RedeemTransactAutoID").Value = outAutoIDs
ExecuteNonQuery(dbCommand)
Catch ex As Exception
Throw New DALException(ex, dbCommand, customerCode, "VoucherRedemption")
Finally
If Not dbCommand Is Nothing Then
dbCommand.Dispose()
End If
If Not dbTrans Is Nothing Then
dbTrans.Dispose()
End If
End Try