在存储过程中回滚与在 C# 代码中回滚

编程入门 行业动态 更新时间:2024-10-25 08:21:40
本文介绍了在存储过程中回滚与在 C# 代码中回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个过程 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# 代码中回滚

本文发布于:2023-11-07 00:45:40,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565097.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过程中   代码   中回滚

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!