transactionscope

TransactionScope maximumTimeout

浪尽此生 提交于 2019-11-29 06:30:17
问题 I use TransactionScope in this code: private void ExecuteSP() { bool IsComplete = false; SqlCommand sqlComm = null; //6 hours!!! TimeSpan ts1 = new TimeSpan(6, 0, 0); try { using (TransactionScope t = new TransactionScope(TransactionScopeOption.RequiresNew, ts1)) { using (SqlConnection sqlConn = new SqlConnection(GetConnectionString())) { //open sql connection sqlConn.Open(); try { //create new sqlCommand sqlComm = new SqlCommand(); for (int i = 1; i <= 2; i++) { IsComplete = true; //This

TransactionScope Error against Sql Server 2000 - The partner transaction manager has disabled its support for remote/network transactions

陌路散爱 提交于 2019-11-28 19:01:46
I am trying to set up a simple transaction for my Linq-to-Sql actions against my Sql 2000 database. Using TransactionScope it looks like this: using (TransactionScope transaction = new TransactionScope()) { try { Store.DBDataContext dc = new Store.DBDataContext(); Store.Product product = GetProduct("foo"); dc.InsertOnSubmit(product); dc.SubmitChanges(); transaction.Complete(); } catch (Exception ex) { throw ex; } } However, i keep getting the following error: The partner transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D025) But, if I

Why doesn't TransactionScope work with Entity Framework?

冷暖自知 提交于 2019-11-28 17:53:26
See the code below. If I initialize more than one entity context, then I get the following exception on the 2nd set of code only . If I comment out the second set it works. {"The underlying provider failed on Open."} Inner: {"Communication with the underlying transaction manager has failed."} Inner: {"Error HRESULT E_FAIL has been returned from a call to a COM component."} Note that this is a sample app and I know it doesn't make sense to create 2 contexts in a row. However, the production code does have reason to create multiple contexts in the same TransactionScope , and this cannot be

Transaction scope timeout on 10 minutes

我与影子孤独终老i 提交于 2019-11-28 17:53:06
I have a long running TransactionScope in C#. I told the scope that it should have a long timespan, but still I get a timeout. What could cause this? TransactionOptions transactionOptions = new TransactionOptions(); transactionOptions.IsolationLevel = IsolationLevel.ReadCommitted; transactionOptions.Timeout = TimeSpan.MaxValue; using (var ts = new TransactionScope(TransactionScopeOption.Required, transactionOptions)) { DoLongCode(); } Hello you can verify maxTimeout in your config file, if you don't have this section on your web.config or app.config Verify your machine.config <configuration>

TransactionScope Prematurely Completed

泪湿孤枕 提交于 2019-11-28 16:56:55
I have a block of code that runs within a TransactionScope and within this block of code I make several calls to the DB. Selects, Updates, Creates, and Deletes, the whole gamut. When I execute my delete I execute it using an extension method of the SqlCommand that will automatically resubmit the query if it deadlocks as this query could potentially hit a deadlock. I believe the problem occurs when a deadlock is hit and the function tries to resubmit the query. This is the error I receive: The transaction associated with the current connection has completed but has not been disposed. The

Multiple SaveChanges calls in entity framework

社会主义新天地 提交于 2019-11-28 16:44:13
I am building my own custom repository, based on entity framework, and I'm creating some extension methods that allow me to save partial view models as entity models so I'm building my own Add and Update methods. Currently, each method has SaveChanges() from DbContext called at the end which means for every model, one call will be invoked. I'm building this base DAL pattern for MVC4 sites which means most of the time I will access 1 model, but it does not have to be the case though. Is it too bad practice to call SaveChanges() for each model when updating i.e. 3 entities or should I add

EF and TransactionScope for both SQL Server and Oracle without escalating/spanning to DTC?

北城余情 提交于 2019-11-28 12:59:01
Can anyone update me on this topic? I want to support both SQL Server and Oracle in my application. Is it possible to have the following code (in BL) working for both SQL Server and Oracle without escalating/spanning to distributed transactions (DTC) ? // dbcontext is created before, same dbcontext will be used by both repositories using (var ts = new TransactionScope()) { // create order - make use of dbcontext, possibly to call SaveChanges here orderRepository.CreateOrder(order); // update inventory - make use of same dbcontext, possibly to call SaveChanges here inventoryRepository

Linq to sql multiple data context in same transaction

岁酱吖の 提交于 2019-11-28 12:43:11
问题 I am working on a project Where I have multiple reposetories to fetch data from differnt tables. All my repositories are independent, they create new dataContext, Add row to table and apply submit changes command. Now if in my service, there is a situation where I have to insert data into multiple tables, but it should happen in one transaction. I can achieve that using TrnasctionScope stuff, but thats needs same dataContext. As I am using StrucutreMap to create my objects, I cant get same

Is there a way to use TransactionScope with an existing connection?

我的梦境 提交于 2019-11-28 09:52:42
I have some code that works like the advised use of TransactionScope, but has an ambient connection instead of an ambient transaction. Is there a way to use a TransactionScope object with an existing connection, or is there an alternative in the .Net framework for this purpose? In fact, there is one way. connection.EnlistTransaction(Transaction.Current) It works and it doesnt promote transaction to distributed if not necessary (contrary to what documentation says) HTH To enlist a connection into a TransactionScope, you need to specify 'Enlist=true' in its connection string and open the

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

℡╲_俬逩灬. 提交于 2019-11-28 09:51:41
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 looks like: create an object and save it inside DB-transaction (commit) create TransactionScope trying to