Visual Studio 2008 TableAdapters and Transactions

A

Andrew Jocelyn

Hi

I've just discovered that the typed DataSet tool now adds a Transaction
property to each TableAdapter. The modifier is internal. It seems to be
undocumented. Are there any examples/best practices on how to use it?

Thanks
Andrew
 
S

Steven Cheng [MSFT]

Hi Andrew,

As for the "Transaction" property of the VS generated TableAdapter, it
actually wrapper the Transaction property on each Command object used in
that TableAdapter. Here is an example of the generated "Transaction"
property (in a certain TableAdapter):

===================
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
internal global::System.Data.SqlClient.SqlTransaction Transaction {
get {
return this._transaction;
}
set {
this._transaction = value;
for (int i = 0; (i < this.CommandCollection.Length); i = (i
+ 1)) {
this.CommandCollection.Transaction =
this._transaction;
}
if (((this.Adapter != null)
&& (this.Adapter.DeleteCommand != null))) {
this.Adapter.DeleteCommand.Transaction =
this._transaction;
}
if (((this.Adapter != null)
&& (this.Adapter.InsertCommand != null))) {
this.Adapter.InsertCommand.Transaction =
this._transaction;
}
if (((this.Adapter != null)
&& (this.Adapter.UpdateCommand != null))) {
this.Adapter.UpdateCommand.Transaction =
this._transaction;
}
}
}
===============

As you can see, when you set its value, it will update all the Command
objects(used in this TableAdapter) and synchronize those commands'
"Transaction' property to the same one. This is used when you use the old
means to perform Transaction in ADO.NET:

#SqlConnection..::.BeginTransaction Method
http://msdn2.microsoft.com/en-us/library/86773566.aspx

By setting the Transaction on the TableAdapeter, you make sure all the
commands involved in the TableAdapter get set to the same transaction.

In ADO.NET 2.0, it provides a more convenient Transaction model:


#Transaction Processing in ADO.NET 2.0
http://www.15seconds.com/issue/040914.htm

#Working with Transactions in ADO.NET
http://www.15seconds.com/issue/040914.htm

Hope this help some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.


--------------------
 
A

Andrew Jocelyn

Hi Steven

Thanks for the information. Actually I'm only interested in grouping
TableAdapters into one SQL transaction. I have a solution using partial
classes with the code generated TableAdapter classes in VS2005. However,
VS2008 now generates a Transaction property which was breaking my code in
the partial classes because I already had a method called Transaction with
the same signiture. I was hoping that grouping TableAdapters together in
VS2008 might be easier so I just wondered if you had any suggestions.

Thanks
Andrew
 
S

Steven Cheng [MSFT]

Thanks for your reply Andrew,

So you originally have your own encapsulatd Transaction property which
conflict with the auto-genearted property in vs 2008, correct? If so, will
the auto-generated one fit your requirement since it also associate with
all the Commands object within the TableAdapter. You can use it to assign a
certain SqlTransaction. Or otherwise, you may using the
System.Transactions namespace's TransactionScope to perform transaction.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top