Hi Sahil,
I've read quite a few of your posts as I searched about TableAdapters and
Transactions.
Perhaps I wasn't quite clear enough with my original post. What I'm trying
to find out is: what is the way the ADO.Net team intended us to use multiple
TableAdapters with transactions? As the class generated is partial, and you
have access to the connection, I can see many different ways of altering the
code for the class or handing it a connection you control, etc, to take
implicit control over the implicit transaction handling - ie you're not
managing the transaction itself, you are moulding the tableadapters into the
right shape so that they don't do the wrong thing and cause the transaction
to get pushed up to the MSDTC. And, of course, you could always just use
data adapters or plain SqlCommands with the old SqlTransaction objects.
However, none of these really click with me. Handling the connection object
yourself so that all adapters posting in a transaction is easy enough when
you're doing all your posting in one method, but can cause a big change in
interface in an enterprise scale system to make sure all relevant code has
the right connection. Altering/adding code to the TableAdapter is even worse
from the perspective of an enterprise scale system.
If you've ever read the blog of people like Rico Mariani, he talks about the
"Pit of success", where using a tool is intuitive to the point that you fall
into using it the best way without realising it. I'm not getting the feeling
that I'm doing this when I use transactions with TableAdapters, so I'm
wondering what the "right" way is supposed to be. It's not that I can't do
it, it's that I haven't found a way to do it yet that doesn't leave a bad
taste in the back of my mouth.
Niall
"Sahil Malik [MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> If you are working with a single database, open your single SqlConnection
> and keep it open throughout the duration of the transaction, that will
> keep the tranasction on LTM for SQL2k5.
>
> The control hasn't been "taken away" from you - you can still do
> SqlTransaction.
>
> Also, please read this
> http://codebetter.com/blogs/sahil.ma.../13/64533.aspx
> and this -
> http://codebetter.com/blogs/sahil.ma.../11/64484.aspx
>
> - Sahil Malik [MVP]
> ADO.NET 2.0 book -
> http://codebetter.com/blogs/sahil.ma.../13/63199.aspx
> -------------------------------------------------------------------------------------------
>
>
> "Niall" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
>> I'm trying out the new TableAdapters in ADO.Net 2.0. I was a bit
>> surprised to see control of transactions being somewhat taken away from
>> me and placed into the System.Transactions namespace. I had a read and
>> saw all the stuff about distributed transactions, which seems quite cool
>> for managing access to multiple resources of different types. However,
>> for plain old SQL Transactions, it seems like if you're not careful, you
>> might end up paying a performance hit.
>>
>> So I wrote a small app that inserts rows in a few tables in one function.
>> This all needs to be inside the one transaction. So I use the
>> TransactionScope, and everything seemed sweet while I was only posting
>> the first TableAdapter. Once I started posted the other two, I received
>> exceptions complaining that the MSDTC was not running. After reading the
>> generated code for the TableAdapters, it appears that what I have to do
>> is ensure that the first adapter's connection is open before it posts
>> (otherwise it will close it again), and that the other adapters all have
>> their connections assigned to be the first adapter's connection. This
>> seems to leave SQLServer 2005 happy enough to do it all on one
>> transaction and not involve the MSDTC.
>>
>> Is this the "proper" way to get around your transaction getting promoted
>> up to the MSDTC? Also, can I/should I close the SqlConnection I manually
>> opened before/after completing the TransactionScope, or should I leave
>> it?
>>
>> Niall
>>
>
>