transactionscope

How can I implement WCF Transaction support on custom class using CoreService?

荒凉一梦 提交于 2019-12-01 16:23:39
I wrote a class to assist in adding & removing Destinations to a Publication Target using the Core Service. Destinations are normally exposed as a string (with XML content) via the Core Service, so I wrote my own wrappers around that, etc. I now have a situation where I need to update 2 publication targets and thought it would be cool to use a transaction scope to ensure that both targets are updated at the same time. I am however struggling with implementing this. Code working (using standard CoreService WCF client): TransactionOptions txOptions = new TransactionOptions { IsolationLevel =

Why is a nested transaction committed even if TransactionScope.Complete() is never called?

一世执手 提交于 2019-12-01 13:25:41
I was testing to see how nested transactions work, and uncovered this disturbing and unexpected behavior. using(TransactionScope otx = new TransactionScope()) using(SqlConnection conn1 = new SqlConnection("Server=S;Database=DB;Trusted_Connection=yes")) using(SqlCommand cmd1 = conn1.CreateCommand()) { conn1.Open(); cmd1.CommandType = CommandType.Text; cmd1.CommandText = "INSERT INTO FP.ACLs (ChangeToken,ACL) VALUES (1,0x)"; cmd1.ExecuteNonQuery(); using(TransactionScope itx = new TransactionScope(TransactionScopeOption.RequiresNew)) using(SqlConnection conn2 = new SqlConnection("Server=S

Why is a nested transaction committed even if TransactionScope.Complete() is never called?

血红的双手。 提交于 2019-12-01 10:16:01
问题 I was testing to see how nested transactions work, and uncovered this disturbing and unexpected behavior. using(TransactionScope otx = new TransactionScope()) using(SqlConnection conn1 = new SqlConnection("Server=S;Database=DB;Trusted_Connection=yes")) using(SqlCommand cmd1 = conn1.CreateCommand()) { conn1.Open(); cmd1.CommandType = CommandType.Text; cmd1.CommandText = "INSERT INTO FP.ACLs (ChangeToken,ACL) VALUES (1,0x)"; cmd1.ExecuteNonQuery(); using(TransactionScope itx = new

Does TransactionScope work with pre-existing connections?

天涯浪子 提交于 2019-12-01 02:17:46
问题 I have a code like this: try { using (TransactionScope scope = new TransactionScope()) { some_db_function(); for (i = 0; i < 10; i++) { some_other_db_function(); } scope.Complete(); } } catch (Exception ex) { MessageBox.Show(ex.Message + " all done transactions will rollback"); } and inside the db functions something like this happens: private void some_db_functions() { using (TransactionScope scope = new TransactionScope()) { //some processing on db scope.Complete(); } } It is supposed to be

Why is my TransactionScope trying to use MSDTC when used in an EF Code First app?

元气小坏坏 提交于 2019-12-01 02:17:03
问题 I have just introduced a TransactionScope use to an MVC3 app using EF 4.3 Code First, against a SQL 2010 Express local DB. When I try a SaveChanges inside the scope, I get a "Provider failed to open" notice, with an inner exception about a missing MSDTC. As far as I know, this should only occur if I used multiple connection strings. I only ever use connections to the one DB, I only have 1 string in the app. I do however use several DbContext instances, but only one across the transaction

Multiple databases(datacontext) on same server without MS DTC

本秂侑毒 提交于 2019-11-30 20:28:42
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 { IsolationLevel = IsolationLevel.ReadUncommitted })) { MSObjectContext.SaveChanges(SaveOptions

Nested Transactions with TransactionScope

风格不统一 提交于 2019-11-30 20:14:27
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 back? Yes. The inner transaction is enrolled in the same scope of the outer one, and the whole thing will

TransactionScope, where is begin transaction on sql profiler?

[亡魂溺海] 提交于 2019-11-30 17:48:19
i need to do something like this on a transaction context using(var context = new Ctx()) { using (TransactionScope tran = new TransactionScope()) { decimal debit = 10M; int id = 1; var data = context.Cashier .Where(w => w.ID == id) .Select(s => new{ s.Money }) .Single(); Cashier cashier = new Cashier(){ ID = id }; context.Cashier.Attach(cashier); cashier.Money = data.Money - debit; context.Entry(cashier).Property(p => p.Money ).IsModified = true; context.SaveChanges(SaveOptions.None); tran.Complete(); } } I'm running sql profiler but can't see begin tran, is that block of code correct? Am I

NHibernate 3.0: TransactionScope and Auto-Flushing

╄→гoц情女王★ 提交于 2019-11-30 15:34:24
问题 In NHibernate 3.0, FlushMode.Auto does not work when running under an ambient transaction only (that is, without starting an NHibernate transaction). Should it? using (TransactionScope scope = new TransactionScope()) { ISession session = sessionFactory.OpenSession(); MappedEntity entity = new MappedEntity() { Name = "Entity", Value = 20 }; session.Save(entity); entity.Value = 30; session.SaveOrUpdate(entity); // This returns one entity, when it should return none var list = session.

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

[亡魂溺海] 提交于 2019-11-30 14:41:32
问题 (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