transactionscope

Am I using TransactionScope and DataContext properly?

不打扰是莪最后的温柔 提交于 2019-12-11 11:54:32
问题 What if I new up some DataContexts, read some data, and then only wrap the SubmitChanges in a TransactionScope? string conn1 = GetConn1(); string conn2 = GetConn2(); using (DataContext1 dc1 = new DataContext1(conn1)) { List<Customer> customers = ReadSomeData(dc1); ModifySomeCustomers(customers); //performs local modification to Customer instances using (DataContext2 dc2 = new DataContext2(conn2)) { List<Order> orders = ReadSomeData(dc2); ModifySomeOrders(orders); //performs local modification

Integration testing using Selenium and NUnit - From UI to DB

隐身守侯 提交于 2019-12-11 11:35:10
问题 I am having some problems while trying to create integration tests with Selenium and NUnit. I'm trying to use Selenium RC in NUnit test to drive my ASP.NET web app, and would like the tests to actually do all the stuff in DB that the real user would do. Naturally it would be nice if the database could get rolled back after Selenium has done it's thing, and i've asserted that db contains the new rows (etc) with the data from the ui. So, here's the setup i have (in some sort of pseudocode):

RavenDB and MsSql inside same transaction scope results in WebException

落爺英雄遲暮 提交于 2019-12-11 11:28:07
问题 In response to another question on stackoverflow RavenDB does not play nicely with Transaction Scope i have created a test case where i isolate my transactions for storing and reading. In my test case i am making a call to a raven document store and a mssql database within the same transaction. But i get a Web Exception. Any ideas why or how to solve it. Below is my code private static string con = "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=TestDB;Data Source=.";

Sending NServiceBus message inside TransactionScope

时间秒杀一切 提交于 2019-12-11 08:29:49
问题 I am trying to use NHibernate to save to a database in the same transaction as sending a message on the bus from inside an MVC application: public void DoSomethingToEntity(Guid id) { var session = _sessionFactory.OpenSession(); CurrentSessionContext.Bind(session); using (var transactionScope = new TransactionScope()) { var myEntity = _session.Get(id); myEntity.DoSomething(); _session.Save(myEntity); _bus.Send(myMessage); transactionScope.Complete(); } session.Dispose(); } In the configuration

DbContext.SaveChanges() visibility within a TransactionScope

浪子不回头ぞ 提交于 2019-12-11 06:24:56
问题 Given a TransactionScope with 2 subsequently opened DbContexts, are changes saved by the first context guaranteed to be visible within the scope of second context? var txOptions = new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }; using (var transaction = new TransactionScope(TransactionScopeOption.Required, txOptions)) { using (var context1 = new MyDbContext()) { context1.Employees.Single(e => e.Id == 1).Salary += 1; // Update context1.Employees.Remove(context1

Does SQL Server Compact (CE) support a RequiresNew transaction scope inside another one?

回眸只為那壹抹淺笑 提交于 2019-12-11 05:59:14
问题 Here's a very simple example using SQL Server CE 3.5 SP1 where I attempt to use a new transaction inside an existing one. using (var db = new MyDataContext(<connection string>)) using (var ts = new TransactionScope()) { db.Thing.InsertOnSubmit(new Thing()); db.SubmitChanges(); using (var ts2 = new TransactionScope(TransactionScopeOption.RequiresNew)) { db.Thing.InsertOnSubmit(new Thing()); db.SubmitChanges(); // exception here ts2.Complete(); } [... do more stuff ...] ts.Complete(); } This

Informix .NET Provider and TransactionScope not rolling back

跟風遠走 提交于 2019-12-11 05:56:22
问题 I have a little proof-of-concept distributed transaction application that is doing a simple insert into two tables -- one a MS SQL Server table, the other an Informix Dynamic Server table. The problem comes when an exception is thrown. If I use the OLE DB driver for Informix, everything works fine -- both inserts roll back; if I use the .NET Data Provider for Informix, the Informix insert does not roll back. Does anyone have any ideas as to what is going on? In the code snippet, you will

The connection object can not be enlisted in transaction scope

家住魔仙堡 提交于 2019-12-11 05:28:27
问题 I am using TransactionScope to test database actions. This is the test class: // Test class private TransactionScope _transactionScope = null; [TestInitialize] public void Initialize() { _transactionScope = new TransactionScope(); } [TestCleanup] public void Cleanup() { if (_transactionScope != null) { _transactionScope.Dispose(); _transactionScope = null; } } [TestMethod] [DeploymentItem("Db.sdf")] public void AddToPresentationsTest() { var item = TestItem(); var db = new DbEntities(); var

TransactionScope functions

删除回忆录丶 提交于 2019-12-11 04:39:14
问题 Working on Transactions in .net. Had a question on flowing transactions through sub functions. Do I need to use dependent transactions if the object context is common across the sub - methods? For example, in the following code - I declare the object context in the constructor of my class (not sure if this is best practice) public class EmployeeRepository { private EmployeeContext ec; public EmployeeRepository() { objectContext = new EmployeeContext(); } public InitTransaction(EmployeeEntity

Using transactions across processes

佐手、 提交于 2019-12-11 01:55:25
问题 I'm trying to use System.Transactions (TransactionScope) to coordinate a set of processes, each of which does some database work. Ultimately all processes need to commit or be rolled back atomically via one parent process. Unfortunately, nothing I've tried so far works. My basic strategy is to TransactionScope in the parent process, save it to a file, and invoke a child process, which loads the file, uses the transaction inside its own TransactionScope, and returns to the parent. But this