You are correct, it is a good idea do all of your distributed transaction work on the same connection when using a lightweight distributed transaction.
As soon as you close the connection we will place it back into a restricted pool from where it won't come out until the dtc is completed. Creating a new connection will force promotion.
Angel
The problem is that, as instructed, we've duly stuck to the "connection pooling" model of using and releasing them ASAP. However, this means that I'd have to change *all* the code to pass the connection around, surly that would mean that connection contention would slow down the throughput. "Between a rock and a hard place", no?
Whithout seeing your code it is hard to make comments. In general when using transactions where you want the best performance and scalability you want your transactions to start as late as possible and to commit them as soon as possible.
When using Distributed transactions you give up a lot of performance to gain two things:
1) transactions that span multiple connections. (In this scenario lightweight transactions do not come into play)
2) A "cleaner" programming model where you have a higher view of the transaction. Usually you would have a set of non transacted functions that do units of work and then you add transaction support by starting a DTC at a higher level and calling these units of work.
In the second case you are already stepping away from best performance and scalability by moving transaction support up, this is true even if you were to use only lightweight transactions. You still have a chance at fairly good performance if you happen to call only one item of work that requires a transaction, but overall you are probably going to be working with full distributed transactions.
Hope this helps,
Angel
The second point is closer the mark. The inner components have no idea (and nor should they) what transaction they're in, that's the responsibility of the controller component. However, the majority of them do need to open database connections and do need to get the uncommitted data associated with the ambient transaction. I don't (think) I have a problem with that. What I find odd is that given the connection pooling works by understanding you're asking for exactly the same connection why can't the LTM understand that it doesn't need to promote the transaction? I'm sure there are reasons for it, but I'm sure people of your vast intelligence
could get around that issue therefore providing the connections were always to exactly the same provider the LTM would have no need to promote to the DTC and we'd all have a wonderful lightweight experience!
I believe Jian answers all your questions on her final post on the thread that you are pointing to.
Bottom line is that the only way to avoid this at the moment is to have a single connection, this pooling limitation may be removed in the future. to make sure of this I would make sure a bug is entered in the product feedback site (or voted on if there is already one there).
Ok, thanks for that, I've posted it at:
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=171884
Please vote for me ;)