Home All Groups Group Topic Archive Search About

Transactions with TableAdapters in ADo.Net 2.0

Author
3 Mar 2006 10:06 AM
Brian Smith
I have a VS2005 C# winforms app connecting to SQL2005. Having discovered
the limitations of the new TableAdapter implementation, and the fact
that if I use System.Transaction on updates to a DataSet with several
related tables then MSDTC is automatically invoked,  I've followed
advice from this newsgroup and elsewhere to implement my own methods in
the TableAdapter classes to apply a SQLTransaction object to each
command (much as I used to do with DataAdapters in ADO 1.1).

This seems to work very well, but I'm puzzled by the fact that when I
trace the events in SQL Profiler I do not see any BEGIN TRAN or COMMIT
statements, even though if I artificially induce a rollback the
transaction is definitely completely rolled back as expected. Is there a
different communication channel for transactions with SQL2005?

brian smith

Author
3 Mar 2006 6:35 PM
Sahil Malik [MVP C#]
There isn't a different channel - it's the same TDS you'd use if you were
using SSMS. But it isn't as direct as SqlConnection.BeginTransaction will
end up calling "BEGIN TRAN" .. in fact, the exact behaviors are a bit
different between the two - ADO.NET and TSQL.

Any specific reason why you're worrying about the exact implementation
detail? I've never really had to worry about it so just curious :)

- Sahil Malik [MVP]
ADO.NET 2.0 book -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
----------------------------------------------------------------------------


Show quote
"Brian Smith" <bsmith@NO.SPAM.schemiotics.co.uk> wrote in message
news:ef2ppoqPGHA.2336@TK2MSFTNGP12.phx.gbl...
>I have a VS2005 C# winforms app connecting to SQL2005. Having discovered
>the limitations of the new TableAdapter implementation, and the fact that
>if I use System.Transaction on updates to a DataSet with several related
>tables then MSDTC is automatically invoked,  I've followed advice from this
>newsgroup and elsewhere to implement my own methods in the TableAdapter
>classes to apply a SQLTransaction object to each command (much as I used to
>do with DataAdapters in ADO 1.1).
>
> This seems to work very well, but I'm puzzled by the fact that when I
> trace the events in SQL Profiler I do not see any BEGIN TRAN or COMMIT
> statements, even though if I artificially induce a rollback the
> transaction is definitely completely rolled back as expected. Is there a
> different communication channel for transactions with SQL2005?
>
> brian smith
Author
3 Mar 2006 7:47 PM
Brian Smith
Thanks Sahil. My only concern is that my transactions really are working
- I'm used to seeing them in the Profiler trace - it just gives extra
confidence that I didn't miss out something somewhere in my code (it
happens)

brian

Sahil Malik [MVP C#] wrote:
Show quote
> There isn't a different channel - it's the same TDS you'd use if you were
> using SSMS. But it isn't as direct as SqlConnection.BeginTransaction will
> end up calling "BEGIN TRAN" .. in fact, the exact behaviors are a bit
> different between the two - ADO.NET and TSQL.
>
> Any specific reason why you're worrying about the exact implementation
> detail? I've never really had to worry about it so just curious :)
>
> - Sahil Malik [MVP]
> ADO.NET 2.0 book -
> http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
> ----------------------------------------------------------------------------
>
>
> "Brian Smith" <bsmith@NO.SPAM.schemiotics.co.uk> wrote in message
> news:ef2ppoqPGHA.2336@TK2MSFTNGP12.phx.gbl...
>> I have a VS2005 C# winforms app connecting to SQL2005. Having discovered
>> the limitations of the new TableAdapter implementation, and the fact that
>> if I use System.Transaction on updates to a DataSet with several related
>> tables then MSDTC is automatically invoked,  I've followed advice from this
>> newsgroup and elsewhere to implement my own methods in the TableAdapter
>> classes to apply a SQLTransaction object to each command (much as I used to
>> do with DataAdapters in ADO 1.1).
>>
>> This seems to work very well, but I'm puzzled by the fact that when I
>> trace the events in SQL Profiler I do not see any BEGIN TRAN or COMMIT
>> statements, even though if I artificially induce a rollback the
>> transaction is definitely completely rolled back as expected. Is there a
>> different communication channel for transactions with SQL2005?
>>
>> brian smith
>
>
Author
3 Mar 2006 8:06 PM
Sahil Malik [MVP C#]
Oh yes they are working :). ADO.NET in fact has checks built in which won't
let you run a SqlCommand without a transaction midway of a transaction
batch - try it.


SM


Show quote
"Brian Smith" <bsmith@NO.SPAM.schemiotics.co.uk> wrote in message
news:eaoQUtvPGHA.1216@TK2MSFTNGP14.phx.gbl...
> Thanks Sahil. My only concern is that my transactions really are working -
> I'm used to seeing them in the Profiler trace - it just gives extra
> confidence that I didn't miss out something somewhere in my code (it
> happens)
>
> brian
>
> Sahil Malik [MVP C#] wrote:
>> There isn't a different channel - it's the same TDS you'd use if you were
>> using SSMS. But it isn't as direct as SqlConnection.BeginTransaction will
>> end up calling "BEGIN TRAN" .. in fact, the exact behaviors are a bit
>> different between the two - ADO.NET and TSQL.
>>
>> Any specific reason why you're worrying about the exact implementation
>> detail? I've never really had to worry about it so just curious :)
>>
>> - Sahil Malik [MVP]
>> ADO.NET 2.0 book -
>> http://codebetter.com/blogs/sahil.malik/archive/2005/05/13/63199.aspx
>> ----------------------------------------------------------------------------
>>
>>
>> "Brian Smith" <bsmith@NO.SPAM.schemiotics.co.uk> wrote in message
>> news:ef2ppoqPGHA.2336@TK2MSFTNGP12.phx.gbl...
>>> I have a VS2005 C# winforms app connecting to SQL2005. Having discovered
>>> the limitations of the new TableAdapter implementation, and the fact
>>> that if I use System.Transaction on updates to a DataSet with several
>>> related tables then MSDTC is automatically invoked,  I've followed
>>> advice from this newsgroup and elsewhere to implement my own methods in
>>> the TableAdapter classes to apply a SQLTransaction object to each
>>> command (much as I used to do with DataAdapters in ADO 1.1).
>>>
>>> This seems to work very well, but I'm puzzled by the fact that when I
>>> trace the events in SQL Profiler I do not see any BEGIN TRAN or COMMIT
>>> statements, even though if I artificially induce a rollback the
>>> transaction is definitely completely rolled back as expected. Is there a
>>> different communication channel for transactions with SQL2005?
>>>
>>> brian smith
>>
Author
4 Mar 2006 11:05 AM
Miha Markic [MVP C#]
Yup, the best way to check it out is to actually try it...

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Show quote
"Sahil Malik [MVP C#]" <contactmethrumyblog@nospam.com> wrote in message
news:eFhis3vPGHA.1108@TK2MSFTNGP09.phx.gbl...
> Oh yes they are working :). ADO.NET in fact has checks built in which
> won't let you run a SqlCommand without a transaction midway of a
> transaction batch - try it.

AddThis Social Bookmark Button