transactionscope

How to support async methods in a TransactionScope with Microsoft.Bcl.Async in .NET 4.0?

主宰稳场 提交于 2020-01-12 04:12:06
问题 I have a method similar to: public async Task SaveItemsAsync(IEnumerable<MyItem> items) { using (var ts = new TransactionScope()) { foreach (var item in items) { await _repository.SaveItemAsync(item); } await _repository.DoSomethingElse(); ts.Complete(); } } This of course has issues because TransactionScope doesn't play nice with async/await. It fails with an InvalidOperationException with the message: "A TransactionScope must be disposed on the same thread that it was created." I read about

TransactionScope not working with Parallel Extensions?

夙愿已清 提交于 2020-01-11 05:14:46
问题 If i do the following: Using scope = New TransactionScope() entries.Content.ReadAs(Of IList(Of WebMaint)).AsParallel.ForAll(Sub(entry) _repos.Update(entry) End Sub) scope.Complete() End Using TransactionScope doesn't work. If i put a breakpoint on the scope.complete no transaction is active and the updates are already complete. If i change it to: Using scope = New TransactionScope() entries.Content.ReadAs(Of IList(Of WebMaint)).ToList().ForEach(Sub(entry) _repos.Update(entry) End Sub) scope

TransactionScope With Files In C# [duplicate]

☆樱花仙子☆ 提交于 2020-01-09 04:50:27
问题 This question already has answers here : How to write a transaction to cover Moving a file and Inserting record in database? (4 answers) Closed 2 years ago . I've been using TransactionScope to work with the database and it feels nice. What I'm looking for is the following: using(var scope=new TransactionScope()) { // Do something with a few files... scope.Complete(); } but obviously this doesn't work -- if there are 20 files, and an exception occurs on the 9th file, all previous 8 remain

ORA-00604 error while batch insertion inside TransactionScope

六月ゝ 毕业季﹏ 提交于 2020-01-06 20:08:42
问题 I am trying to batch insert 100k+ items to my Oracle db using ADO.NET inside a TransactionScope. Like this: using (TransactionScope transaction = new TransactionScope()) { while(/* Pagination logic - send insertion command on every 250 items */) { using (OracleCommand command = new OracleCommand(query, connection)) { command.ArrayBindCount = 250; //Add parameters command.Parameters.Add(":BLAH", OracleDbType.Long); command.Parameters[0].Value = LUC.ToArray(); command.ExecuteNonQuery(); //Error

Transaction Scope in Oracle with ASP.NET

本小妞迷上赌 提交于 2020-01-05 08:16:17
问题 using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope()) { TableAdapter.Insert("test","test"); ts.Complete(); } I am getting this error :Unable to load DLL ' oramts.dll ': The specified module could not be found. (Exception from HRESULT: 0x8007007E) I have Oracle Client installed with Oracle services for Windows Transaction even the DLL file oramts.dll is in [ORALCE_HOME]/bin Thanks in advance 回答1: http://jelle.druyts.net/2006/06/25

EF5 Code First TransactionScope without escalating to MSDTC

时光怂恿深爱的人放手 提交于 2020-01-05 06:52:51
问题 I'm using EF5 code first, and I need to wrap multiple calls to SaveChanges() in the same transaction. I'm relatively new to using transactionScope, and can't seem to tweak the options on it to accomplish what I'm looking to do. The following code resides in a service class that gets injected with an instance of my DbContext class. I do not create additional instances of DbContext anywhere in this class. At first I tried the following. The code is nice and clean, but it attempts to escalate to

EF5 Code First TransactionScope without escalating to MSDTC

拟墨画扇 提交于 2020-01-05 06:51:18
问题 I'm using EF5 code first, and I need to wrap multiple calls to SaveChanges() in the same transaction. I'm relatively new to using transactionScope, and can't seem to tweak the options on it to accomplish what I'm looking to do. The following code resides in a service class that gets injected with an instance of my DbContext class. I do not create additional instances of DbContext anywhere in this class. At first I tried the following. The code is nice and clean, but it attempts to escalate to

.net detect distributed transaction

人盡茶涼 提交于 2020-01-04 13:04:29
问题 In my application I use the following pattern for calling the DB: //do a transaction using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required)) { OperationOnDb1(); //when we open the connection to the “other db” in this call, the transaction would become distributed OperationOnDb2(); //transaction is now distributed transaction.Complete(); } The problem is that Operation1 and Operation2 90% of the time use the same db ... but there are cases (bugs) when they

DocumentDb write within a transactionscope

╄→尐↘猪︶ㄣ 提交于 2020-01-04 03:32:05
问题 I am trying to use a DocumentDb write as a part of a transaction like below - using (var scope = new TransactionScope) { //first transaction //write to document db //third transaction } I observed that if the third transaction fails, documentDb write is not rolled back and I still see the document in the collection. The first transaction (NEventStore in this case) rolls back perfectly. Does anyone know if DocumentDb supports TrnasactionScope. What if I have a nested transaction? Thanks! Edit:

Understanding transactionscope timeouts

爱⌒轻易说出口 提交于 2020-01-04 03:14:48
问题 My current understanding of transactionscope timeouts. If a transaction has been running longer than the set timeout time it throws an exception when transaction.complete() is called. So if the processing within the transaction has been going on for X minutes we still would have to wait X minutes after which the transaction.complete is called. In our case, we are using transactionscope from within a webservice - the end user of the web request will have to wait for X minutes before the