我有一个过程 Proc1 调用另一个过程 Proc2,并且两者都带有BEGIN TRANSCTION"如果我在第二个过程中遇到错误,它将回滚两个过程.好的!
I have a procedure Proc1 that calls another procedure Proc2, and both with "BEGIN TRANSCTION" If i get an error at the second procedure, it will rollback both procedures. OK!
但在我的 C# 代码中,我也有这个
But inside my C# code, i have also this
... dbCommand.Transaction.Commit(); dbCnn.Close(); } catch (Exception ex) { if (dbCommand.Transaction != null) **dbCommand.Transaction.Rollback();** if (dbCnn.State == ConnectionState.Open) dbCnn.Close(); throw ex; }dbCommand.Transaction.Rollback();"知道我说的是哪笔交易吗?而且如果我有两个事务吃了同一个程序,没有标签,C#回滚正确的事务会不会有问题?
Does "dbCommand.Transaction.Rollback();" knows which transaction I am talking about? And if I have two transactions ate the same procedure, without label, will it be a problem for C# rollback the right transaction?
推荐答案dbCommand.Transaction.Rollback();"知道我是哪笔交易谈论?
Does "dbCommand.Transaction.Rollback();" knows which transaction I am talking about?
没有.它也不在乎.它回滚在连接级别包装所有内容的事务.里面的一切都是这个交易的一部分.
No. It also does not care. It rolls back the transaction that is wrapping everything on connection level. Everything inside is part of this transaction.
如果我有两个交易吃了同样的程序,没有标签,C#回滚正确的事务会不会有问题?
And if I have two transactions ate the same procedure, without label, will it be a problem for C# rollback the right transaction?
您不能有两个交易.事务形成层次结构.上面的代码回滚了整个顶级连接级事务.您在存储过程中打开的所有其他事务都是该事务的一部分.
You can not have two transactions. Transactions form a hierarchy. The code above rolls back the whole top level connection level transaction. Every other transaction you open in a sstored procedure is part of this transaction.
更多推荐
在存储过程中回滚与在 C# 代码中回滚
发布评论