transactionscope

Using TransactionScope with Entity Framework 6

非 Y 不嫁゛ 提交于 2019-11-30 11:57:49
问题 What I can't understand is if its possible to make changes to the context and get the changes in the same transaction before its commited. This is what I´m looking for: using (var scope = new TransactionScope(TransactionScopeOption.Required)) { using (var context = new DbContext()) { //first I want to update an item in the context, not to the db Item thisItem = context.Items.First(); thisItem.Name = "Update name"; context.SaveChanges(); //Save change to this context //then I want to do a

How does TransactionScope work?

删除回忆录丶 提交于 2019-11-30 11:51:06
问题 When Method1() instantiates a TransactionScope and calls Method2() that also instantiates a TransactionScope , how does .NET know both are in the same scope? I believe it doesn't use static methods internally otherwise it wouldn't work well on multithreaded applications like ASP.NET. Is it possible to create my own TransactionScope-like class or does the original one use special features those just Microsoft knows how they work? 回答1: Hope this helps: http://msdn.microsoft.com/en-us/magazine

TransactionScope TransactionAborted Exception - transaction not rolled back. Should it be?

只愿长相守 提交于 2019-11-30 11:21:16
(SQL SERVER 2008) If a Transaction Timeout error occurs within a TransactionScope (.Complete()) would you expect the transaction to be rolled back? Update: The error is actually being thrown in the closing curly brace (i.e. .Dispose()), not .Complete(). Full error is: The transaction has aborted. System.Transactions.TransactionAbortedException TransactionAbortedException System.Transactions.TransactionAbortedException: The transaction has aborted. ---> System.TimeoutException: Transaction Timeout --- End of inner exception stack trace --- at System.Transactions.TransactionStateAborted

TransactionScope Error against Sql Server 2000 - The partner transaction manager has disabled its support for remote/network transactions

自作多情 提交于 2019-11-30 06:31:24
问题 I am trying to set up a simple transaction for my Linq-to-Sql actions against my Sql 2000 database. Using TransactionScope it looks like this: using (TransactionScope transaction = new TransactionScope()) { try { Store.DBDataContext dc = new Store.DBDataContext(); Store.Product product = GetProduct("foo"); dc.InsertOnSubmit(product); dc.SubmitChanges(); transaction.Complete(); } catch (Exception ex) { throw ex; } } However, i keep getting the following error: The partner transaction manager

Nested Transactions with TransactionScope

♀尐吖头ヾ 提交于 2019-11-30 04:08:41
问题 If you have somehting like this: IBinaryAssetStructureRepository rep = new BinaryAssetStructureRepository(); var userDto = new UserDto { id = 3345 }; var dto = new BinaryAssetBranchNodeDto("name", userDto, userDto); using (var scope1 = new TransactionScope()) { using(var scope2 = new TransactionScope()) { //Persist to database rep.CreateRoot(dto, 1, false); scope2.Complete(); } scope1.Dispose(); } dto = rep.GetByKey(dto.id, -1, false); Will the inner TransactionScope scope2 also be rolled

Using TransactionScope with Entity Framework 6

五迷三道 提交于 2019-11-30 01:47:27
What I can't understand is if its possible to make changes to the context and get the changes in the same transaction before its commited. This is what I´m looking for: using (var scope = new TransactionScope(TransactionScopeOption.Required)) { using (var context = new DbContext()) { //first I want to update an item in the context, not to the db Item thisItem = context.Items.First(); thisItem.Name = "Update name"; context.SaveChanges(); //Save change to this context //then I want to do a query on the updated item on the current context, not against the db Item thisUpdatedItem = context.Items

Linq to sql multiple data context in same transaction

二次信任 提交于 2019-11-29 18:07:20
I am working on a project Where I have multiple reposetories to fetch data from differnt tables. All my repositories are independent, they create new dataContext, Add row to table and apply submit changes command. Now if in my service, there is a situation where I have to insert data into multiple tables, but it should happen in one transaction. I can achieve that using TrnasctionScope stuff, but thats needs same dataContext. As I am using StrucutreMap to create my objects, I cant get same data context, so my transaction fails. Here is how my objects are. interface IConnection { MyDataContext

Difference between Implicit and Explicit Transaction

倾然丶 夕夏残阳落幕 提交于 2019-11-29 16:47:50
问题 What is the difference between Implicit and Explicit transaction in Sql Server 2008? What happens in TransactionScope background? I'm using TransactionScope but in Sql server profiler I don't see "Begin transaction..." statement. How does it work? 回答1: Implicit Transactions: http://msdn.microsoft.com/en-us/library/ms188317.aspx SET IMPLICIT_TRANSACTIONS { ON | OFF} http://msdn.microsoft.com/en-us/library/ms187807.aspx Basically, in c# when you set the TransactionScope to Implicit, it calls

Data committed even though System.Transactions.TransactionScope.Commit() not called

江枫思渺然 提交于 2019-11-29 11:03:02
Under what circumstances can code wrapped in a System.Transactions.TransactionScope still commit, even though an exception was thrown and the outermost scope never had commit called? There is a top-level method wrapped in using (var tx = new TransactionScope()) , and that calls methods that also use TransactionScope in the same way. I'm using typed datasets with associated tableadapters. Could it be that the commands in the adapter aren't enlisting for some reason? Do any of you know how one might check whether they are enlisting in the ambient TransactionScope or not? The answer turned out to

Database transactions in Zend Framework: Are they isolated?

本秂侑毒 提交于 2019-11-29 09:35:23
问题 Using Zend Framework, I need to (1) read a record from a MySQL database, and (2) immediately write back to that record to indicate that it has been read. I don't want other processes or queries to be able to read from or write to the same record in between steps (1) and (2). I was considering using a transaction for these steps. If I use the following methods, will that fulfil my requirements? Zend_Db_Adapter_Abstract::beginTransaction() Zend_Db_Adapter_Abstract::commit() Zend_Db_Adapter