久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如果發生錯誤, using 語句是否會回滾數據庫事務

Will a using statement rollback a database transaction if an error occurs?(如果發生錯誤, using 語句是否會回滾數據庫事務?)
本文介紹了如果發生錯誤, using 語句是否會回滾數據庫事務?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我在 using 語句中有一個 IDbTransaction,但我不確定如果在 using 語句中拋出異常,它是否會回滾.我知道 using 語句將強制調用 Dispose()...但是有誰知道 Rollback() 是否也是如此?

I've got an IDbTransaction in a using statement but I'm unsure if it will be rolled back if an exception is thrown in a using statement. I know that a using statement will enforce the calling of Dispose()...but does anyone know if the same is true for Rollback()?

更新:另外,我是否需要像下面那樣顯式調用 Commit() 或者這也會由 using 語句處理?

Update: Also, do I need to call Commit() explicitly as I have below or will that also be taken care of by the using statement?

我的代碼看起來像這樣:

My code looks sort of like this:

using Microsoft.Practices.EnterpriseLibrary.Data;

...

using(IDbConnection connection = DatabaseInstance.CreateConnection())
{
    connection.Open();

    using(IDbTransaction transaction = connection.BeginTransaction())
    {
       //Attempt to do stuff in the database
       //potentially throw an exception
       transaction.Commit();
    }
}

推薦答案

事務類的 Dispose 方法執行回滾,而 Oracle 的類不執行.因此,從事務的角度來看,它依賴于實現.

Dispose method for transaction class performs a rollback while Oracle's class doesn't. So from transaction's perspective it's implementation dependent.

另一方面,連接對象的 using 語句要么關閉與數據庫的連接,要么在重置連接后將連接返回到池中.無論哪種情況,都應該回滾未完成的事務.這就是為什么異常永遠不會留下活動事務的原因.

The using statement for the connection object on the other hand would either close the connection to the database or return the connection to the pool after resetting it. In either case, the outstanding transactions should be rolled back. That's why an exception never leaves an active transaction lying around.

另外,是的,您應該顯式調用 Commit().

Also, yes, you should call Commit() explicitly.

這篇關于如果發生錯誤, using 語句是否會回滾數據庫事務?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

LINQ to SQL and Concurrency Issues(LINQ to SQL 和并發問題)
Yield return from a try/catch block(try/catch 塊的收益回報)
Should I call Parameters.Clear when reusing a SqlCommand with a transation?(重用帶有事務的 SqlCommand 時,我應該調用 Parameters.Clear 嗎?)
Does SqlTransaction need to have Dispose called?(SqlTransaction 是否需要調用 Dispose?)
Reason for System.Transactions.TransactionInDoubtException(System.Transactions.TransactionInDoubtException 的原因)
How do I use TransactionScope with MySql and Entity Framework? (getting Multiple simultaneous connections...are not currently supported error)(如何將 TransactionScope 與 MySql 和實體框架一起使用?(獲取多個同時連接...目前不
主站蜘蛛池模板: 在线免费观看毛片 | 超级乱淫av片免费播放 | 性一交一乱一伦视频免费观看 | 中文字幕高清在线 | 毛片在线看看 | 日本精品视频在线 | 成人免费福利视频 | 久久久久久高清 | 一区二区三区视频在线观看 | 精品久久久久久久久久久久久 | 欧美日韩久久 | 青草视频在线 | 日韩插插| 日韩一区二区三区视频在线观看 | 一区二区三区视频在线 | 久久精品一区二区三区四区 | 国产精品久久久久久中文字 | 国产98色在线 | 日韩 | 狠狠的日 | 九九在线 | 亚洲精品一区二区三区丝袜 | 91在线视频国产 | 日韩欧美国产精品一区二区 | 国产精品国色综合久久 | 欧美日韩综合视频 | 一级免费a | 久久久www成人免费精品 | 天天操夜夜拍 | 亚洲网站在线观看 | 人人擦人人干 | 欧美黄页| 久久国产美女视频 | 欧美日韩中文字幕在线 | 亚洲精品福利视频 | a级片播放| 69视频在线播放 | 久久i| 日韩精品在线观看一区二区三区 | 国产高清免费 | 久久久人成影片一区二区三区 | 午夜男人的天堂 |