tags:

views:

470

answers:

3

EDIT: I am only accessing 1 database but a DTC transaction IS being created. I can see it in the DTC Transaction List GUI (Component services plugin). Why is this?

I need to perform a transaction (several insert commands) against 1 database.

Should I be using TransactionScope or IDbTransaction (connection.BeginTransaction)?

TransactionScope seems to be newer … but should it just be used for 2-phase commits?

Thanks

+2  A: 

TransactionScope will only escalate to a distributed transaction if it detects more than one connection. This means that TransactionScope is just as lightweight as BeginTransaction for local transactions and TransactionScope is a lot easier to use.

Jakob Christensen
A: 

As long as you use a single connection and do not close and re-open during a TransactionScope, it should not promote to a distributed transaction. If you do not have the DTC service running on your machine it will throw an exception if it tries to promote. If the DTC running, you will be non the wiser of the promotion except for a slight pause.

Mitch Wheat
A: 

In the vast majority of cases, TransactionScope is much nicer to use, especially in conjunction with "using" blocks.

Be careful though, if you use SQL Server 2000. It does not play well with TransactionScope and will always escalate to a distributed transaction.

See this link for some details.

Denis Troller