transactionscope

NHibernate with TransactionScope

一个人想着一个人 提交于 2019-11-26 15:50:03
问题 Can anyone give me a quick overview of using TransactionScope with NHibernate? Do I need to do anything special with the session/IEnlistmentNotification/etc. to get this to work? Are there any pitfalls that I should worry about? For example, can I replace all of my hibernate transactions: var transaction = session.BeginTransaction(); try { // code transaction.Commit(); } catch (Exception) { transaction.Rollback(); } with this?: using (var scope = new TransactionScope()) { // code scope

Get TransactionScope to work with async / await

旧时模样 提交于 2019-11-26 15:02:47
I'm trying to integrate async / await into our service bus. I implemented a SingleThreadSynchronizationContext based on this example http://blogs.msdn.com/b/pfxteam/archive/2012/01/20/10259049.aspx . And it works fine, except for one thing: TransactionScope . I await for stuff inside the TransactionScope and it break the TransactionScope . TransactionScope doesn't seems to play nice with the async / await , certainly because it store things in the thread using ThreadStaticAttribute . I get this exception : "TransactionScope nested incorrectly.". I tried to save TransactionScope data before

Nested/Child TransactionScope Rollback

限于喜欢 提交于 2019-11-26 14:12:53
问题 I am trying to nest TransactionScopes (.net 4.0) as you would nest Transactions in SQL Server, however it looks like they operate differently. I want my child transactions to be able to rollback if they fail, but allow the parent transaction to decide whether to commit/rollback the whole operation. The problem is when the first complete occurs, the transaction is rolled back. I realize that complete is different to commit. A greatly simplified example of what I am trying to do: static void

SQL Server: Isolation level leaks across pooled connections

霸气de小男生 提交于 2019-11-26 12:51:17
As demonstrated by previous Stack Overflow questions ( TransactionScope and Connection Pooling and How does SqlConnection manage IsolationLevel? ), the transaction isolation level leaks across pooled connections with SQL Server and ADO.NET (also System.Transactions and EF, because they build on top of ADO.NET). This means, that the following dangerous sequence of events can happen in any application: A request happens which requires an explicit transaction to ensure data consistency Any other request comes in which does not use an explicit transaction because it is only doing uncritical reads.

Under what circumstances is an SqlConnection automatically enlisted in an ambient TransactionScope Transaction?

僤鯓⒐⒋嵵緔 提交于 2019-11-26 12:33:54
What does it mean for an SqlConnection to be "enlisted" in a transaction? Does it simply mean that commands I execute on the connection will participate in the transaction? If so, under what circumstances is an SqlConnection automatically enlisted in an ambient TransactionScope Transaction? See questions in code comments. My guess to each question's answer follows each question in parenthesis. Scenario 1: Opening connections INSIDE a transaction scope using (TransactionScope scope = new TransactionScope()) using (SqlConnection conn = ConnectToDB()) { // Q1: Is connection automatically enlisted

Database.BeginTransaction vs Transactions.TransactionScope

本秂侑毒 提交于 2019-11-26 11:58:15
问题 What is the difference between System.Transactions.TransactionScope and EF6\'s Database.BeginTransaction ? Could someone give a small example or just explain which one to use when with a clear difference? P.S: In my project, I\'m using EF6. I\'ve already read the documentation but it didn\'t help much. Also looked up the examples but they are rather using SqlConnection.BeginTransaction and now MS has introduced this new Database.BeginTransaction in EF6. 回答1: I found out the answer in Entity

C# controlling a transaction across multiple databases

≯℡__Kan透↙ 提交于 2019-11-26 11:09:12
问题 Say I\'m having a Windows Form application which connected to n databases, with n connections opened simultaneously. What I\'m looking for is to do a transaction with all of those databases in one go. For example if I were to have 2 database connections : using (ITransaction tx1 = session1.OpenTransaction()) { using (ITransaction tx2 = session2.OpenTransaction()) { // Do the query thingy here } } Writing all that is fine at first, but things get kind of redundant when I wanted to query here

How to use TransactionScope in C#?

亡梦爱人 提交于 2019-11-26 10:29:01
问题 I am trying to use TransactionScope , but keep getting the exception below. The app is running on a different machine than the database, if that matters. I am using SQL Server 2005. Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool. using (TransactionScope tsTransScope = new TransactionScope()) { //Do stuff here tsTransScope.Complete(); }

Why is System.Transactions TransactionScope default Isolationlevel Serializable

喜欢而已 提交于 2019-11-26 09:18:51
问题 I am just wondering what a good reason to use Serializable as the default Isolationlevel may be when creating a System.Transactions TransactionScope , because I cannot think of any (and it seems that you cannot change the default via web/app.config so you always have to set it in your code) using(var transaction = TransactionScope()) { ... //creates a Transaction with Serializable Level } Instead I always have to write boilerplate code like this: var txOptions = new System.Transactions

The transaction manager has disabled its support for remote/network transactions

自古美人都是妖i 提交于 2019-11-26 09:17:24
问题 I\'m using SQL Server and ASP.NET. I have the following function: Using js = daoFactory.CreateJoinScope() Using tran = New Transactions.TransactionScope() \'... tran.Complete() End Using End Using However, the exception \' The transaction manager has disabled its support for remote/network transactions. \' is thrown. Description of JoinScope: Public Class JoinScope Implements IJoinScope Implements IDisposable \'... End Class I have worked this way in another application with the same