RE: Visual Studio 2008 TableAdapters and Transactions



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[i].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:
msdnmg@xxxxxxxxxxxxxx

==================================================
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.


--------------------
From: "Andrew Jocelyn" <j055@xxxxxxxxxxxxxxxxx>
Subject: Visual Studio 2008 TableAdapters and Transactions
Date: Tue, 25 Mar 2008 17:15:05 -0000

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




.



Relevant Pages

  • Re: Transactions + multiple table adapters
    ... TA's connection by using the Connection property. ... Public Shared Sub SetTransaction(ByVal tableAdapter As Object, ... For Each command As SqlCommand In commandCollection ... stored procedure on the second table adapter - all within a transaction. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Strongly typed dataset and transactions
    ... The problem is that the automatically generated TableAdapter from the xsd ... to the InsertCommand, so you cannot set its transaction! ... I am using VB.NET to write to an Access database, ...
    (microsoft.public.dotnet.framework.adonet)
  • Transactions + multiple table adapters
    ... with two DataTables each having a TableAdapter. ... use the insert command on the first TableAdapter and then execute a stored ... procedure on the second table adapter - all within a transaction. ... Problem is that each TableAdapter uses it's own connection. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: TableAdapter with Transactions
    ... bet is to simply open the connection, wrap it in a TransactionScope and run ... sure your transaction isn't promoting the MSDTC. ... SqlTransaction TableAdapter.BeginTransaction ... This way, you can use the TableAdapter to start/end transactions, and ENSURE ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: TableAdapter with Transactions
    ... > a) If you are using Sql Server 2005, and *only one* connection, your best ... > make sure your transaction isn't promoting the MSDTC. ... > TableAdapter and add a BeginTransaction method on the table adapter ... > SqlTransaction TableAdapter.BeginTransaction ...
    (microsoft.public.dotnet.framework.adonet)