transactionscope

C# controlling a transaction across multiple databases

China☆狼群 提交于 2019-11-27 04:30:33
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 and there, and not to mention the possibility to adding a new connection. What I wanted is to loop all of

One transaction with multiple dbcontexts

梦想与她 提交于 2019-11-27 04:21:55
问题 I am using transactions in my unit tests to roll back changes. The unit test uses a dbcontext, and the service i'm testing uses his own. Both of them are wrapped in one transaction, and one dbcontext is in the block of the other. The thing is, when the inner dbcontext saves his changes, it's not visible to the outer dbcontext (and i don't think it's because the other dbcontext might already have the object loaded). Here is the example: [TestMethod] public void EditDepartmentTest() { using

How to use TransactionScope in C#?

二次信任 提交于 2019-11-27 03:20:45
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(); } Edit I made some changes based on the feedback. Now I'm getting this error: "Error HRESULT E_FAIL has

What is the reason of “Transaction context in use by another session”

廉价感情. 提交于 2019-11-27 03:16:27
问题 I'm looking for a description of the root of this error: "Transaction context in use by another session". I get it sometimes in one of my unittests so I can't provider repro code. But I wonder what is "by design" reason for the error. UPDATE: the error returns as SqlException from SQL Server 2008. A place where I get the error seems to be single-threaded. But probably I have unittests interaction as I get the error where run several tests at once (MSTest in VS2008sp1). But the failing test

Entity Framework 6 async operations and TranscationScope

天涯浪子 提交于 2019-11-27 02:26:23
问题 I search on stackoverflow but could not find a similar question, please point me if there is already one. I was trying to implement a generic reusable repository with both sync and async operations but with my little knowledge with Entity Framework and Unit Of Work I'm struggling to find the correct way to implement it. I have added some variations on SaveAndCommit operation but don't know what is the best way to do it with transaction and async. ----Edit---- As per my understanding

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

佐手、 提交于 2019-11-27 00:04:23
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 environment without a problem, but here I have this problem. What could I do to fix the issue? Make sure that the

TransactionScope: Avoiding Distributed Transactions

孤街醉人 提交于 2019-11-26 22:48:22
问题 I have a parent object (part of a DAL) that contains, amongst other things, a collection ( List<t> ) of child objects. When I'm saving the object back to the DB, I enter/update the parent, and then loop through each child. For maintainability, I've put all the code for the child into a separate private method. I was going to use standard ADO Transactions, but on my travels, I stumbled across the TransactionScope object, which I believe will enable me to wrap all DB interaction in the parent

Stored Procedure without transaction in Entity Framework

淺唱寂寞╮ 提交于 2019-11-26 21:50:38
问题 I'm calling a stored procedure in Entity Framework 6 that can create Databases and tables if necessary. It is throwing the error; Message "CREATE DATABASE statement not allowed within multi-statement transaction.\r\nALTER DATABASE statement not allowed within multi-statement transaction.\r\nDatabase 'CoreSnapshotJS3' does not exist. Make sure that the name is entered correctly." string I do not want it in a transaction, and have used this to supress the transaction using (var transation = new

How does TransactionScope roll back transactions?

岁酱吖の 提交于 2019-11-26 17:19:02
I'm writing an integration test where I will be inserting a number of objects into a database and then checking to make sure whether my method retrieves those objects. My connection to the database is through NHibernate...and my usual method of creating such a test would be to do the following: NHibernateSession.BeginTransaction(); //use nhibernate to insert objects into database //retrieve objects via my method //verify actual objects returned are the same as those inserted NHibernateSession.RollbackTransaction(); However, I've recently found out about TransactionScope which apparently can be

C# - System.Transactions.TransactionScope

て烟熏妆下的殇ゞ 提交于 2019-11-26 16:35:22
问题 I was curious about the TransactionScope class. For the most part, I assume it was intended for database connections (which is what I've used it for). My question, is can you put any code in the using-block of a TransactionScope to make it transactional? MS documentation is not clear on this. If it can be used to make code other than database connections transactional, which ones are supported? It would seem crazy to me if it could make System.IO.File operations transactional. 回答1: