transactionscope

Where should I perform action when implementing IEnlistmentNotification?

有些话、适合烂在心里 提交于 2019-12-22 06:20:48
问题 I am trying to create a custom "resource manager" by implementing IEnlistmentNotification interface. This interface has following methods: Prepare() Commit() Rollback() InDoubt() While it's clear that rollback code should go in Rollback() method I am not sure in which method should I implement the code that performs the actual operation? Should it go in Prepare() or Commit() or maybe some other custom method in the class that will be called from outer code from inside of TransactionScope

TransactionScope Complete() doesn't commit the transaction before exiting the USING statement

送分小仙女□ 提交于 2019-12-22 03:45:56
问题 I am experiencing this weird behavior where the transaction gets committed only when the using exits and not when calling scope.Complete(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)) { scope.Complete(); // data still doesn't show in db } // now shows in db How do I commit the transaction before exiting the using statement? 回答1: from the documentation: The actual work of commit between the resources manager happens at the End Using statement if

TransactionScope Complete() doesn't commit the transaction before exiting the USING statement

百般思念 提交于 2019-12-22 03:45:22
问题 I am experiencing this weird behavior where the transaction gets committed only when the using exits and not when calling scope.Complete(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)) { scope.Complete(); // data still doesn't show in db } // now shows in db How do I commit the transaction before exiting the using statement? 回答1: from the documentation: The actual work of commit between the resources manager happens at the End Using statement if

Call stored procedure inside transaction using Entity Framework

帅比萌擦擦* 提交于 2019-12-22 01:29:49
问题 I am trying to run the following transaction using Entity Framework. Inside transaction scope I call stored procedure from the DB. using (mother_Entities entitiesContext = context.Value) { using (var transactionScope = new TransactionScope()) { // a lot of create, insert, update operations goes here ... entitiesContext.SaveChanges(); //Execute stored procedure: var paramMessage = new ObjectParameter("MESSAGE", ""); var paramMotherid = new ObjectParameter("MOTHERID", motherProductId); var

TransactionScope alternative without DTC

一个人想着一个人 提交于 2019-12-21 01:19:47
问题 are there any alternative to transactionScope which does not need to enable DTC?? In the transaction I need to make two operations: Create one user (using membership - sql membership provider) Do one insert operation. 回答1: TransactionScope uses the LTM - Lightweight Transaction Manager in .Net. Only if you open more than one connection in the same transaction or go between databases, should TransactionScope promote the transaction to the 2PC-based TX-manager, DTC. For MS SQL Server 2008 and

Using TransactionScope around a stored procedure with transaction in SQL Server 2014

余生长醉 提交于 2019-12-20 09:04:39
问题 I am using C# and ADO.Net with a TransactionScope to run a transaction in an ASP.Net app. This transaction is supposed to save some data across multiple tables and then send an email to subscribers. Question : is it a valid use of TransactionScope , when it includes a call to a stored procedure that has its own transaction in SQL Server 2014, or should I remove the SQL transaction statements i.e. begin tran , commit tran and rollback tran statements from the stored procedure being called

Alternative to Save point when using System.Transactions

一世执手 提交于 2019-12-20 01:37:07
问题 How can I use classes from System.Transactions namespace to achieve similar effect as I can get when using SqlTransaction.Save(savePoint) and SqlTransaction.Rollback(savePoint). The effect of using these two methods is ability to create named save point in the running transaction and in case of issue rollback only to the save point (operations created before save point are not rolled back). 回答1: Save Points are database specific in part of their implementation. Oracle implements them, and

Multiple databases(datacontext) on same server without MS DTC

守給你的承諾、 提交于 2019-12-19 03:06:07
问题 I'm using EF5.0 with SQL server 2008. I have two databases on the same server instance. I need to update tables on both databases and want them to be same transaction. So I used the TransactionScope. Below is the code - public void Save() { var MSObjectContext = ((IObjectContextAdapter)MSDataContext).ObjectContext; var AWObjectContext = ((IObjectContextAdapter)AwContext).ObjectContext; using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions {

Locking a table with a select in Entity Framework

时间秒杀一切 提交于 2019-12-18 07:45:08
问题 I need to do something like this select * from myTable with (xlock,holdlock) using Entity Framework. Is this possible? I've opened a TransactionScope with the Serializable isolation level but my selects are not locking the tables. I'd like them to lock until I complete the transaction scope. 回答1: It is possible but you have to issue the SQL you can't add the locking hint when using LINQ (as far as I know): ObjectContext.ExecuteStoreCommand( string.Format("select 1 from [{0}] with (tablockx,

Can't I call a stored procedure from Entity Framework inside a transaction scope?

血红的双手。 提交于 2019-12-18 04:13:02
问题 I have a method that uses Entity Framework to do some changes/inserts in different entities, all this inside a single transaction scope. These changes works very well. My problem has began when I needed to use a stored procedure in the middle of these operations. The procedure does only an insert in one table, and has no explicit declaration of transactions. I've tried declaring a transaction and commiting there also, but the problem was the same. Can't I call a stored procedure from Entity