<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Brant Burnett&#039;s Development Blog &#187; ADO.NET</title>
	<atom:link href="http://btburnett.com/category/netframework/adonet/feed" rel="self" type="application/rss+xml" />
	<link>http://btburnett.com</link>
	<description></description>
	<lastBuildDate>Fri, 25 Mar 2011 13:39:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Using Transactions With DataSets</title>
		<link>http://btburnett.com/2008/03/using-transactions-with-datasets.html</link>
		<comments>http://btburnett.com/2008/03/using-transactions-with-datasets.html#comments</comments>
		<pubDate>Tue, 25 Mar 2008 08:42:00 +0000</pubDate>
		<dc:creator>Brant Burnett</dc:creator>
				<category><![CDATA[ADO.NET]]></category>

		<guid isPermaLink="false">http://www.btburnett.com/?p=4</guid>
		<description><![CDATA[One of the major shortcomings of the ADO.NET dataset system, in my opinion, is the lack of support for transactions. In .NET 2.0 this situation was somewhat addressed by the addition of the System.Transactions namespace. However, this namespace has two flaws when it comes to using it with a DataSet. First, if you open more [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-family:verdana;font-size:85%;">One of the major shortcomings of the ADO.NET dataset system, in my opinion, is the lack of support for transactions.  In .NET 2.0 this situation was somewhat addressed by the addition of the System.Transactions namespace.  However, this namespace has two flaws when it comes to using it with a DataSet.  First, if you open more than one database connection within the same TransactionScope, it will use the Distributed Transaction Coordinator (MSDTC) instead of more efficient and configuration free database transactions.  Second, if you require backwards compatibility with SQL 2000, it will ALWAYS use the MSDTC even if you open just a single database connection. The first issue can be addressed by opening the connection in advance and passing it to each TableAdapter that you use.  Note that you&#8217;ll need to change the Connection property on the TableAdapter from Friend (internal) to Public in the DataSet designer if the DataSet is in a DLL.</span><br /><span style="font-family:verdana;font-size:85%;"></span><br /><span style="font-family:verdana;font-size:85%;">The second issue is a bit trickier to solve.  In this case, you also need to open a single database connection as before, but then use an old fashioned SqlTransaction instead of the System.Transactions namespace.  Then both the SqlConnection and SqlTransaction need to be set on each TableAdapter.  This can be done by adding a special helper function to the partial class for the TableAdapter, as shown below.</span></p>
<p><span style="font-family:courier new;font-size:70%">Namespace DataSetTableAdapters</span><br /><span style="font-family:Courier New;font-size:70%;"></span><br /><span style="font-family:Courier New;font-size:70%;margin-left: 2em;">Partial Class TableAdapter</span><br /><span style="font-family:Courier New;font-size:70%;"></span><br /><span style="font-family:courier new;font-size:70%;margin-left: 4em;">Public Sub SetConnection(ByVal cn As SqlConnection, trans As SqlTransaction)</span><br /><span style="font-family:courier new;font-size:70%;margin-left: 6em;">Connection = cn</span><br /><span style="font-family:courier new;font-size:70%;margin-left: 6em;">For Each cmd As SqlCommand In Me.CommandCollection</span><br /><span style="font-family:courier new;font-size:70%;margin-left: 8em;">cmd.Transaction = trans</span><br /><span style="font-family:courier new;font-size:70%;margin-left: 6em;">Next</span><br /><span style="font-family:courier new;font-size:70%;margin-left: 6em;">Adapter.UpdateCommand.Transaction = trans</span><br /><span style="font-family:courier new;font-size:70%;margin-left: 6em;">Adapter.InsertCommand.Transaction = trans</span><br /><span style="font-family:courier new;font-size:70%;margin-left: 6em;">Adapter.DeleteCommand.Transaction = trans</span><br /><span style="font-family:courier new;font-size:70%;margin-left: 4em;">End Sub</span><br /><span style="font-family:Courier New;font-size:70%;"></span><br /><span style="font-family:Courier New;font-size:70%;margin-left: 2em;">End Class</span><br /><span style="font-family:Courier New;font-size:70%;"></span><br /><span style="font-family:Courier New;font-size:70%;">End Namespace</span></p>
]]></content:encoded>
			<wfw:commentRss>http://btburnett.com/2008/03/using-transactions-with-datasets.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

