transactionscope

Setting the database connection when using a TransactionScope

Does the database connection have to be set inside a TransactionScope? Or can I set it in the ctor and then have instance methods create up a TransactionScope? EDIT: e.g. Public Sub New() Dim conn = new SqlConnection(...connection string) Public Sub SomeClassMethod() using ts as new TransactionScope //conn has already b...

Why is TransactionScope using a distributed transaction when I am only using LinqToSql and Ado.Net

We are having problems on one machine, with the error message: "MSDTC on server XXX is unavailable." The code is using a TransactionScope to wrap some LingToSql database code; there is also some raw Ado.net inside of the transaction. As only a single sql database (2005) is being accessed, why is a distributed transaction being ...

WCF Transaction Scope SQL insert table lock

Hi All, I have two services talking to two different Data-stores (i.e SQL). I am using transactionscope: eg: using(TransactionScope scope = new TransactionScope()) { service1.InsertUser(user);//Insert to SQL Service 1 table User service2.SavePayment(payment);//Save payment SQL Service 2 table payment scope.Complete(); } ...

Nested/Child TransactionScope Rollback

I am trying to nest TransactionScopes (.net 4.0) as you would nest Transactions in SQL Server, however it looks like they operate differently. I want my child transactions to be able to rollback if they fail, but allow the parent transaction to decide whether to commit/rollback the whole operation. The problem is when the first complete...

Database doesn't update using TransactionScope

I have a client trying to communicate with a WCF service in a transactional manner. The client passes some data to the service and the service adds the data to its database accordingly. For some reason, the new data the service submits to its database isn't being persisted. When I have a look at the table data in the Server Explorer no n...

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

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...

Passing around a SqlConnection

I have created a TransactionScope and within the scope various items are created and updated in the database. During this process I make a lot of calls to the database. Originally I opened a SqlConnection in the beginning of the TransactionScope and passed it around to any function that made a DB call then I closed the connection after a...

Under what circumstances is an SqlConnection automatically enlisted in an ambient TransactionScope Transaction?

What does it mean for an SqlConnection to be "enlisted" in a transaction? Does it simply mean that commands I execute on the connection will participate in the transaction? If so, under what circumstances is an SqlConnection automatically enlisted in an ambient TransactionScope Transaction? See questions in code comments. My guess to...

TransactionScope Prematurely Completed

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 ...

Delete Stored Proc Deadlock in Sql Server

I am having the following deadlock in SQL Server 2005 with a specific delete stored proc and I can't figure out what I need to do to remedy it. <deadlock-list> <deadlock victim="processf3a868"> <process-list> <process id="processcae718" taskpriority="0" logused="0" waitresource="KEY: 7:72057594340311040 (b50041b389fe)" waittime="6...

Question About TransactionScope in .NET

using (TransactionScope scope = new TransactionScope()) { int updatedRows1 = custPh.Update(cust.CustomerID, tempPh1, 0); int updatedRows2 = custPh.Update(cust.CustomerID, tempPh2, 1); int updatedRows3 = cust.Update(); if (updatedRows1 > 0 && updatedRows2 > 0 && updatedRows3 > 0) { scope.Complete(); } } ...

is TransactionScope usable for sql operations, is it doing the same thing as Sqltransaction ?

can I do something like this: using (var scope = new TransactionScope()) { using (var conn = new SqlConnection(Cs)) { using (var cmd = conn.CreateCommand()) { cmd.CommandType = CommandType.StoredProcedure; ....

Two Phase Commit with IEnlistmentNotification interface

When Commit is called (for the implementation of IEnlistmentNotification) can I just throw an exception to indicate I want the transaction to rollback? ...

how to make a context for the instances of a class.

Hi, I need to make a context or an ambient for the instances of a class and know if other instances are running. Something like TransactionScopes. Example: private void method1() { using (myclass mc1 = new myclass()) { method2(); } } private void method2() { using (myclass mc2 = new myclass()) { ...

NHibernate with multiple databases and transactions

We are having a few problems understanding how best to use NHibernate. We typically have a relatively large number of quite small (in terms of number of tables) SQL Server databases rather than one database with a lot of objects. We are looking at various options for handling multiple session factories and probably have this under cont...

Will transactionscope work over multiple calls to different services?

I'm writing some merge functionality in C# asp.NET MVC2. I am also using using Linq2SQL. I have a block of code which calls two services, MessageService and UserService. These both in term call their appropriate repositories and make the amendments to the db. Each repository declares it's own instance of the repository so I'm thinking t...

What is the best way to rollback a .net transaction?

This question is related to my question: http://stackoverflow.com/questions/3072986/sql-server-and-transactionscope-with-msdtc-sporadically-cant-get-connection I'm doing some transaction programming using the .net TransactionScope class. If I understand correctly, I can do some SQL operations within a transaction by wrapping the SQL ca...

TransactionScope not rolling back with SqlDataAdapter.Update

I'm using SqlDataAdapter.Update with DataTables to update two SQL tables in a single transaction. If either insert fails I want to roll back all data. This is my code: using (var conn = new SqlConnection(_connectionString)) { conn.Open(); using (var scope = new TransactionScope()) { // Insert first table usi...

How .net allows nested transactions with TransactionScopeOption

I have learned that Oracle & sql server database does not allow nested transactions. Then how does c# allow us to perform nested transactions using transactionscopeoption? ...

TransactionScope: Avoiding Distributed Tansactions

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...