<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:georss="http://www.georss.org/georss" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Scott Klueppel's Blog - Transactions</title>
    <link>http://offroadcoder.com/</link>
    <description>making the hard line look easy</description>
    <language>en-us</language>
    <copyright>Scott Klueppel</copyright>
    <lastBuildDate>Sat, 08 May 2010 15:32:25 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.1.8102.813</generator>
    <managingEditor>me@offroadcoder.com</managingEditor>
    <webMaster>me@offroadcoder.com</webMaster>
    <item>
      <trackback:ping>http://offroadcoder.com/Trackback.aspx?guid=88ec2d3e-12d8-4fa0-b1d4-e82f7d6c677e</trackback:ping>
      <pingback:server>http://offroadcoder.com/pingback.aspx</pingback:server>
      <pingback:target>http://offroadcoder.com/PermaLink,guid,88ec2d3e-12d8-4fa0-b1d4-e82f7d6c677e.aspx</pingback:target>
      <dc:creator>Scott Klueppel</dc:creator>
      <georss:point>30.109017 -81.497099</georss:point>
      <wfw:comment>http://offroadcoder.com/CommentView,guid,88ec2d3e-12d8-4fa0-b1d4-e82f7d6c677e.aspx</wfw:comment>
      <wfw:commentRss>http://offroadcoder.com/SyndicationService.asmx/GetEntryCommentsRss?guid=88ec2d3e-12d8-4fa0-b1d4-e82f7d6c677e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Despite its pitiful adoption in the developer community, I am implementing Transactional
NTFS (TxF) transactions using the Microsoft.KtmIntegration.TransactedFile class. This
allows me to reap the benefits of TransactionScope and distributed transactions for
file operations (e.g. creates, updates, deletes). This is the only missing piece for
typical transactional business applications. With the “KTM” and “KtmRm for Distributed
Transactions” services, available only on Vista, Windows 7, and Windows Server 2008,
file operations will roll back if the TransactionScope is not completed. 
</p>
        <p>
There’s just one problem… Transactional NTFS does not work with file shares. I can’t
remember the last time I put a “C:\FileStore” reference in a config file. A friendly
share like “\\server\FileStore” is always preferred, especially since DFS came about.
Attempting to use a share results in the following error message: 
</p>
        <blockquote>
          <p>
            <font color="#000080" size="2" face="Consolas">The remote server or share does not
support transacted file operations</font>
          </p>
        </blockquote>
        <p>
Don’t read this as “your remote server” or “your remote share”, but rather “all remote
servers and shares”. As mentioned in <a href="      http://msdn.microsoft.com/en-us/library/aa365738(v=VS.85).aspx" target="_blank">this
MSDN article</a>, TxF is not supported by the CIFS/SMB protocols. The error was probably
written with the expectation that one day some remote servers and shares would support
TxF. I emailed Microsoft about it and received a response fairly quickly. The response
was simply: 
</p>
        <blockquote>
          <p>
“We understand the need and have plans to eventually support TxF over SMB2, but we’re
not there yet and are not ready to announce if or when this will be supported. When
it is the documentation will be updated.”
</p>
        </blockquote>
        <p>
I’m not getting my hopes up, but Windows Server 2011 looks to be our only hope before
.NET changes beyond recognition and TxF is a distant memory. Until then, I wrapped
up all of my TxF code in a WCF service and install that service on the server with
the <em>FileStore</em> folder. 
</p>
        <p>
MSDN article – When to Use Transactional NTFS 
</p>
        <p>
      <a href="http://msdn.microsoft.com/en-us/library/aa365738(v=VS.85).aspx">http://msdn.microsoft.com/en-us/library/aa365738(v=VS.85).aspx</a></p>
        <p>
TxF Sandbox – Sample Projects (including Microsoft.KtmIntegration.TransactedFile) 
</p>
        <p>
      <a href="http://offroadcoder.com/content/binary/TxFSandbox.zip">TxFSandbox.zip</a></p>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=88ec2d3e-12d8-4fa0-b1d4-e82f7d6c677e" />
      </body>
      <title>The remote server or share does not support transacted file operations</title>
      <guid isPermaLink="false">http://offroadcoder.com/PermaLink,guid,88ec2d3e-12d8-4fa0-b1d4-e82f7d6c677e.aspx</guid>
      <link>http://offroadcoder.com/2010/05/08/TheRemoteServerOrShareDoesNotSupportTransactedFileOperations.aspx</link>
      <pubDate>Sat, 08 May 2010 15:32:25 GMT</pubDate>
      <description>&lt;p&gt;
Despite its pitiful adoption in the developer community, I am implementing Transactional
NTFS (TxF) transactions using the Microsoft.KtmIntegration.TransactedFile class. This
allows me to reap the benefits of TransactionScope and distributed transactions for
file operations (e.g. creates, updates, deletes). This is the only missing piece for
typical transactional business applications. With the “KTM” and “KtmRm for Distributed
Transactions” services, available only on Vista, Windows 7, and Windows Server 2008,
file operations will roll back if the TransactionScope is not completed. 
&lt;p&gt;
There’s just one problem… Transactional NTFS does not work with file shares. I can’t
remember the last time I put a “C:\FileStore” reference in a config file. A friendly
share like “\\server\FileStore” is always preferred, especially since DFS came about.
Attempting to use a share results in the following error message: &lt;blockquote&gt; 
&lt;p&gt;
&lt;font color="#000080" size="2" face="Consolas"&gt;The remote server or share does not
support transacted file operations&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Don’t read this as “your remote server” or “your remote share”, but rather “all remote
servers and shares”. As mentioned in &lt;a href="      http://msdn.microsoft.com/en-us/library/aa365738(v=VS.85).aspx" target="_blank"&gt;this
MSDN article&lt;/a&gt;, TxF is not supported by the CIFS/SMB protocols. The error was probably
written with the expectation that one day some remote servers and shares would support
TxF. I emailed Microsoft about it and received a response fairly quickly. The response
was simply: &lt;blockquote&gt; 
&lt;p&gt;
“We understand the need and have plans to eventually support TxF over SMB2, but we’re
not there yet and are not ready to announce if or when this will be supported. When
it is the documentation will be updated.”
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
I’m not getting my hopes up, but Windows Server 2011 looks to be our only hope before
.NET changes beyond recognition and TxF is a distant memory. Until then, I wrapped
up all of my TxF code in a WCF service and install that service on the server with
the &lt;em&gt;FileStore&lt;/em&gt; folder. 
&lt;p&gt;
MSDN article – When to Use Transactional NTFS 
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href="http://msdn.microsoft.com/en-us/library/aa365738(v=VS.85).aspx"&gt;http://msdn.microsoft.com/en-us/library/aa365738(v=VS.85).aspx&lt;/a&gt; 
&lt;p&gt;
TxF Sandbox – Sample Projects (including Microsoft.KtmIntegration.TransactedFile) 
&lt;p&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href="http://offroadcoder.com/content/binary/TxFSandbox.zip"&gt;TxFSandbox.zip&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=88ec2d3e-12d8-4fa0-b1d4-e82f7d6c677e" /&gt;</description>
      <comments>http://offroadcoder.com/CommentView,guid,88ec2d3e-12d8-4fa0-b1d4-e82f7d6c677e.aspx</comments>
      <category>.NET Framework</category>
      <category>C#</category>
      <category>MSDTC</category>
      <category>Transactions</category>
      <category>WCF</category>
    </item>
    <item>
      <trackback:ping>http://offroadcoder.com/Trackback.aspx?guid=2d946739-b527-41a7-8422-d29f4149e47a</trackback:ping>
      <pingback:server>http://offroadcoder.com/pingback.aspx</pingback:server>
      <pingback:target>http://offroadcoder.com/PermaLink,guid,2d946739-b527-41a7-8422-d29f4149e47a.aspx</pingback:target>
      <dc:creator>Scott Klueppel</dc:creator>
      <georss:point>30.109017 -81.497099</georss:point>
      <wfw:comment>http://offroadcoder.com/CommentView,guid,2d946739-b527-41a7-8422-d29f4149e47a.aspx</wfw:comment>
      <wfw:commentRss>http://offroadcoder.com/SyndicationService.asmx/GetEntryCommentsRss?guid=2d946739-b527-41a7-8422-d29f4149e47a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In a <a href="http://offroadcoder.com/2009/01/29/TheFlowedTransactionCouldNotBeUnmarshaled.aspx" target="_blank">previous
post</a>, I discussed solutions to the dreaded “<em>The flowed transaction could not
be unmarshaled” </em>error commonly experienced when using MSDTC transactions with
WCF, SQL, TxF, etc. I have once again experienced the un-trusted domain scenario,
and can now report with certainty that adding hosts file entries on both machines
will correct the problem. Testing this solution with DTCPing.exe between the two machines
proves that making only the hosts file change acquaints the client and server and
allows distributed transactions to occur.
</p>
        <p>
You will find many blog and forum post non-solutions. Adding the hosts file entry
or the equivalent domain redirects are the only solutions when working with two machines
in disparate, un-trusted domains. Some of the non-solutions you’ll find go so far
as to say to change your SQL connection string to prevent current (ambient) transaction
enlistment. Not quite a complete solution as your first rollback unit test will fail.
</p>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=2d946739-b527-41a7-8422-d29f4149e47a" />
      </body>
      <title>The flowed transaction could not be unmarshaled - Untrusted Domains update</title>
      <guid isPermaLink="false">http://offroadcoder.com/PermaLink,guid,2d946739-b527-41a7-8422-d29f4149e47a.aspx</guid>
      <link>http://offroadcoder.com/2010/03/16/TheFlowedTransactionCouldNotBeUnmarshaledUntrustedDomainsUpdate.aspx</link>
      <pubDate>Tue, 16 Mar 2010 02:54:48 GMT</pubDate>
      <description>&lt;p&gt;
In a &lt;a href="http://offroadcoder.com/2009/01/29/TheFlowedTransactionCouldNotBeUnmarshaled.aspx" target="_blank"&gt;previous
post&lt;/a&gt;, I discussed solutions to the dreaded “&lt;em&gt;The flowed transaction could not
be unmarshaled” &lt;/em&gt;error commonly experienced when using MSDTC transactions with
WCF, SQL, TxF, etc. I have once again experienced the un-trusted domain scenario,
and can now report with certainty that adding hosts file entries on both machines
will correct the problem. Testing this solution with DTCPing.exe between the two machines
proves that making only the hosts file change acquaints the client and server and
allows distributed transactions to occur.
&lt;/p&gt;
&lt;p&gt;
You will find many blog and forum post non-solutions. Adding the hosts file entry
or the equivalent domain redirects are the only solutions when working with two machines
in disparate, un-trusted domains. Some of the non-solutions you’ll find go so far
as to say to change your SQL connection string to prevent current (ambient) transaction
enlistment. Not quite a complete solution as your first rollback unit test will fail.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=2d946739-b527-41a7-8422-d29f4149e47a" /&gt;</description>
      <comments>http://offroadcoder.com/CommentView,guid,2d946739-b527-41a7-8422-d29f4149e47a.aspx</comments>
      <category>SQL</category>
      <category>Transactions</category>
      <category>WCF</category>
    </item>
    <item>
      <trackback:ping>http://offroadcoder.com/Trackback.aspx?guid=6828fc29-242f-440e-b9b7-07396459410e</trackback:ping>
      <pingback:server>http://offroadcoder.com/pingback.aspx</pingback:server>
      <pingback:target>http://offroadcoder.com/PermaLink,guid,6828fc29-242f-440e-b9b7-07396459410e.aspx</pingback:target>
      <dc:creator>Scott Klueppel</dc:creator>
      <georss:point>30.109017 -81.497099</georss:point>
      <wfw:comment>http://offroadcoder.com/CommentView,guid,6828fc29-242f-440e-b9b7-07396459410e.aspx</wfw:comment>
      <wfw:commentRss>http://offroadcoder.com/SyndicationService.asmx/GetEntryCommentsRss?guid=6828fc29-242f-440e-b9b7-07396459410e</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Thank you, Mikael Sand (and Bing)!
</p>
        <p>
          <a href="http://blogical.se/blogs/mikael_sand/archive/2009/08/28/configuring-ws-atomic-transaction-support-in-windows-7-64-bit.aspx">http://blogical.se/blogs/mikael_sand/archive/2009/08/28/configuring-ws-atomic-transaction-support-in-windows-7-64-bit.aspx</a>
        </p>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=6828fc29-242f-440e-b9b7-07396459410e" />
      </body>
      <title>Enable WS-AT on 64-bit Vista or Windows 7</title>
      <guid isPermaLink="false">http://offroadcoder.com/PermaLink,guid,6828fc29-242f-440e-b9b7-07396459410e.aspx</guid>
      <link>http://offroadcoder.com/2009/10/08/EnableWSATOn64bitVistaOrWindows7.aspx</link>
      <pubDate>Thu, 08 Oct 2009 05:51:21 GMT</pubDate>
      <description>&lt;p&gt;
Thank you, Mikael Sand (and Bing)!
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://blogical.se/blogs/mikael_sand/archive/2009/08/28/configuring-ws-atomic-transaction-support-in-windows-7-64-bit.aspx"&gt;http://blogical.se/blogs/mikael_sand/archive/2009/08/28/configuring-ws-atomic-transaction-support-in-windows-7-64-bit.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=6828fc29-242f-440e-b9b7-07396459410e" /&gt;</description>
      <comments>http://offroadcoder.com/CommentView,guid,6828fc29-242f-440e-b9b7-07396459410e.aspx</comments>
      <category>MSDTC</category>
      <category>Transactions</category>
      <category>WCF</category>
    </item>
    <item>
      <trackback:ping>http://offroadcoder.com/Trackback.aspx?guid=c6b29bd9-3388-43b7-b52b-4944aee7e848</trackback:ping>
      <pingback:server>http://offroadcoder.com/pingback.aspx</pingback:server>
      <pingback:target>http://offroadcoder.com/PermaLink,guid,c6b29bd9-3388-43b7-b52b-4944aee7e848.aspx</pingback:target>
      <dc:creator>Scott Klueppel</dc:creator>
      <georss:point>30.109017 -81.497099</georss:point>
      <wfw:comment>http://offroadcoder.com/CommentView,guid,c6b29bd9-3388-43b7-b52b-4944aee7e848.aspx</wfw:comment>
      <wfw:commentRss>http://offroadcoder.com/SyndicationService.asmx/GetEntryCommentsRss?guid=c6b29bd9-3388-43b7-b52b-4944aee7e848</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">The <a href="http://www.jaxcodecamp.com">2009
Jacksonville Code Camp</a> was a great success. Many thanks to Bayer, Brandy, and
everyone else that made it happen. The bar has been set really high for future Jacksonville
code camps, and for the rest of Florida too. 
<br /><br />
My session on Transactional WCF Services went well. Many great questions and compliments
after the session. If you attended and have any unanswered questions, please email
me. 
<br /><br />
You can download the session files below. It contains staged versions of all of the
transaction modes we discussed. It also contains a tracing solution and tracing result
files to view the client and host tracing files in Client/Service mode. Also see my
previous post on using the <a href="http://offroadcoder.com/2008/06/19/ServiceTraceViewer.aspx">Service
Trace Viewer</a>. It also contains a few demo projects that we didn't get to in the
one-hour session. 
<br /><br />
Files/Solutions included in Session Archive: 
<ul><li>
PowerPoint slides 
</li><li>
Transaction Promotion Code Snippet 
</li><li>
Testing database backup 
</li><li>
Testing SQL script (query and cleanup between tests) 
</li><li>
IDesign ServiceModelEx Project (used by all included Solutions) 
</li><li>
Code Demo Solutions</li></ul><p>
Code Demos include:
</p><table border="0" cellspacing="0" cellpadding="3"><tbody><tr><td valign="top" width="20">
1.</td><td valign="top">
TransactionScope - Shows how single/multiple resource managers affect which Transaction
Manager is chosen to handle the scoped transaction. Also gives first look at transaction
promotion detection. 
</td></tr><tr><td valign="top" width="20">
2a.</td><td valign="top">
Mode None - WCF transaction mode with which no transactions are created or flowed
from the calling client. 
</td></tr><tr><td valign="top" width="20">
2b.</td><td valign="top">
Mode Service - WCF transaction mode with which no transactions are flowed from the
calling client, but a transaction is created for your service operation. 
</td></tr><tr><td valign="top" width="20">
2c.</td><td valign="top">
Mode Client - WCF transaction mode with which a transaction is required to be flowed,
and the service will only use the client transaction.</td></tr><tr><td valign="top" width="20">
2d.</td><td valign="top">
Mode Client/Service - WCF transaction mode with which a client transaction will be
flowed and used by the service, if available. If no client transaction is flowed,
a transaction will be provided automatically for the service operation.</td></tr><tr><td valign="top" width="20">
3.</td><td valign="top">
Explicit Voting - Shows how explicit voting with a session-mode service is performed
using OperationContext.Current.SetTransactionComplete(). 
</td></tr><tr><td valign="top" width="20">
4a.</td><td valign="top">
Testing Various Resource Managers - Shows how a client can use a single TransactionScope
to call several services (some transactional, some non-transactional), a database
stored procedure, and an IDesign volatile resource manager Transactional&lt;int&gt;<int>
.
</int></td></tr><tr><td valign="top" width="20">
4b.</td><td valign="top">
Testing Services - Provides a host project for a transactional service and a non-transactional
service used in 4a. 
</td></tr><tr><td valign="top" width="20">
5a.</td><td valign="top">
Tracing - Same as 2d. modified with the additional app.config settings in the client
and host projects to allow for service tracing to .svclog files. 
</td></tr><tr><td valign="top" width="20">
5b.</td><td valign="top">
Tracing Results - Stored results from executing 5a. in case you don't want to load
the database and actually run the projects. The .stvproj file can be opened directly
in the Service Trace Viewer. On the "Activity" table, click on the activity "Process
action 'http://services/gotjeep.net/GpsTrackServiceContract/SubmitTrack'" then click
on the "Graph" tab. You will see that the client and host activities where the arrow
moves from client to host (send and receive message, respectively) show the OleTxTransaction
in "Headers." The next activity in the host reads "The transaction '5bd25b08-848c-409d-9163-6303b9138382:1'
was flowed to operation 'SubmitTrack'."</td></tr></tbody></table><p>
 
</p><p>
Download the session files: 
<br /><a href="content/binary/TransactionalWCF.zip">TransactionalWCF.zip (854 KB)</a></p><img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=c6b29bd9-3388-43b7-b52b-4944aee7e848" /></body>
      <title>Code Camp Session Files</title>
      <guid isPermaLink="false">http://offroadcoder.com/PermaLink,guid,c6b29bd9-3388-43b7-b52b-4944aee7e848.aspx</guid>
      <link>http://offroadcoder.com/2009/09/03/CodeCampSessionFiles.aspx</link>
      <pubDate>Thu, 03 Sep 2009 03:34:34 GMT</pubDate>
      <description>The &lt;a href="http://www.jaxcodecamp.com"&gt;2009 Jacksonville Code Camp&lt;/a&gt; was a great
success. Many thanks to Bayer, Brandy, and everyone else that made it happen. The
bar has been set really high for future Jacksonville code camps, and for the rest
of Florida too. 
&lt;br&gt;
&lt;br&gt;
My session on Transactional WCF Services went well. Many great questions and compliments
after the session. If you attended and have any unanswered questions, please email
me. 
&lt;br&gt;
&lt;br&gt;
You can download the session files below. It contains staged versions of all of the
transaction modes we discussed. It also contains a tracing solution and tracing result
files to view the client and host tracing files in Client/Service mode. Also see my
previous post on using the &lt;a href="http://offroadcoder.com/2008/06/19/ServiceTraceViewer.aspx"&gt;Service
Trace Viewer&lt;/a&gt;. It also contains a few demo projects that we didn't get to in the
one-hour session. 
&lt;br&gt;
&lt;br&gt;
Files/Solutions included in Session Archive: 
&lt;ul&gt;
&lt;li&gt;
PowerPoint slides 
&lt;li&gt;
Transaction Promotion Code Snippet 
&lt;li&gt;
Testing database backup 
&lt;li&gt;
Testing SQL script (query and cleanup between tests) 
&lt;li&gt;
IDesign ServiceModelEx Project (used by all included Solutions) 
&lt;li&gt;
Code Demo Solutions&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Code Demos include:
&lt;/p&gt;
&lt;table border="0" cellspacing="0" cellpadding="3"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="20"&gt;
1.&lt;/td&gt;
&lt;td valign="top"&gt;
TransactionScope - Shows how single/multiple resource managers affect which Transaction
Manager is chosen to handle the scoped transaction. Also gives first look at transaction
promotion detection. 
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="20"&gt;
2a.&lt;/td&gt;
&lt;td valign="top"&gt;
Mode None - WCF transaction mode with which no transactions are created or flowed
from the calling client. 
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="20"&gt;
2b.&lt;/td&gt;
&lt;td valign="top"&gt;
Mode Service - WCF transaction mode with which no transactions are flowed from the
calling client, but a transaction is created for your service operation. 
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="20"&gt;
2c.&lt;/td&gt;
&lt;td valign="top"&gt;
Mode Client - WCF transaction mode with which a transaction is required to be flowed,
and the service will only use the client transaction.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="20"&gt;
2d.&lt;/td&gt;
&lt;td valign="top"&gt;
Mode Client/Service - WCF transaction mode with which a client transaction will be
flowed and used by the service, if available. If no client transaction is flowed,
a transaction will be provided automatically for the service operation.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="20"&gt;
3.&lt;/td&gt;
&lt;td valign="top"&gt;
Explicit Voting - Shows how explicit voting with a session-mode service is performed
using OperationContext.Current.SetTransactionComplete(). 
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="20"&gt;
4a.&lt;/td&gt;
&lt;td valign="top"&gt;
Testing Various Resource Managers - Shows how a client can use a single TransactionScope
to call several services (some transactional, some non-transactional), a database
stored procedure, and an IDesign volatile resource manager Transactional&amp;lt;int&amp;gt;&lt;int&gt;
.
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="20"&gt;
4b.&lt;/td&gt;
&lt;td valign="top"&gt;
Testing Services - Provides a host project for a transactional service and a non-transactional
service used in 4a. 
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="20"&gt;
5a.&lt;/td&gt;
&lt;td valign="top"&gt;
Tracing - Same as 2d. modified with the additional app.config settings in the client
and host projects to allow for service tracing to .svclog files. 
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="20"&gt;
5b.&lt;/td&gt;
&lt;td valign="top"&gt;
Tracing Results - Stored results from executing 5a. in case you don't want to load
the database and actually run the projects. The .stvproj file can be opened directly
in the Service Trace Viewer. On the "Activity" table, click on the activity "Process
action 'http://services/gotjeep.net/GpsTrackServiceContract/SubmitTrack'" then click
on the "Graph" tab. You will see that the client and host activities where the arrow
moves from client to host (send and receive message, respectively) show the OleTxTransaction
in "Headers." The next activity in the host reads "The transaction '5bd25b08-848c-409d-9163-6303b9138382:1'
was flowed to operation 'SubmitTrack'."&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Download the session files: 
&lt;br&gt;
&lt;a href="content/binary/TransactionalWCF.zip"&gt;TransactionalWCF.zip (854 KB)&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=c6b29bd9-3388-43b7-b52b-4944aee7e848" /&gt;</description>
      <comments>http://offroadcoder.com/CommentView,guid,c6b29bd9-3388-43b7-b52b-4944aee7e848.aspx</comments>
      <category>.NET Framework</category>
      <category>C#</category>
      <category>Dev Community</category>
      <category>Dev Tools</category>
      <category>MSDTC</category>
      <category>Transactions</category>
      <category>WCF</category>
    </item>
    <item>
      <trackback:ping>http://offroadcoder.com/Trackback.aspx?guid=08cef9e9-c8f3-49a5-bd38-dcb303bb9c52</trackback:ping>
      <pingback:server>http://offroadcoder.com/pingback.aspx</pingback:server>
      <pingback:target>http://offroadcoder.com/PermaLink,guid,08cef9e9-c8f3-49a5-bd38-dcb303bb9c52.aspx</pingback:target>
      <dc:creator>Scott Klueppel</dc:creator>
      <georss:point>30.109017 -81.497099</georss:point>
      <wfw:comment>http://offroadcoder.com/CommentView,guid,08cef9e9-c8f3-49a5-bd38-dcb303bb9c52.aspx</wfw:comment>
      <wfw:commentRss>http://offroadcoder.com/SyndicationService.asmx/GetEntryCommentsRss?guid=08cef9e9-c8f3-49a5-bd38-dcb303bb9c52</wfw:commentRss>
      <slash:comments>7</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <div style="width: 550px">
          <p>
“Do not anticipate trouble, or worry about what may never happen. Keep in the sunlight.” 
</p>
          <p>
  
</p>
          <p align="right">
- Benjamin Franklin
</p>
        </div>
        <p>
  
</p>
        <p>
It’s obvious that Mr. Franklin didn’t have to deal with bad data, bad code, or even
the occasional hiccup. In the real world, there is “trouble” and we need to not only
anticipate that trouble, but also worry about what may never happen. Simply “keeping
in the sunlight” won’t maintain data or application state integrity. In the real world
we need transactions! 
</p>
        <p>
  
</p>
        <p>
Since .NET 2.0, we’ve had the privilege of using <em>System.Transactions.TransactionScope</em> to
manage our transactions with very few headaches. One of the headaches that almost
everyone experiences is MSDTC. One of the oldest and most elusive topics on the web.
There are tons of blog and forum posts directing our fellow developers to check their
firewall settings for every MSDTC problem. The latest MSDTC hiccup I have seen comes
in the beautifully packaged error message: 
</p>
        <blockquote>
          <p>
            <strong>The flowed transaction could not be unmarshaled. The following exception occurred:
Communication with the underlying transaction manager has failed.</strong>
          </p>
        </blockquote>
        <p>
The what could not be what? You can read some <a href="http://msdn.microsoft.com/en-us/library/cc229833(PROT.10).aspx " target="_blank">MSDN
documentation on the topic</a> which will probably cause you more pain. If you are
seeing this error message, there’s only a few things that may be wrong. 
</p>
        <ol>
          <li>
MSDTC Settings 
<ul><li>
Check the MSDTC settings on the machine that is initiating the transaction. If “Allow
Outbound” is not checked, then it won’t allow the transaction in progress to be flowed
to the next machine in the transaction chain. Check the box and restart MSDTC… it
should work.</li></ul></li>
          <li>
Un-Trusted Domains 
<ul><li>
I have seen this error when you are trying to flow transactions between machines that
are in un-trusted domains. Machines in different domains that do not trust each other
block the antiquated, yet necessary, WINS resolution between the two machines. MSDTC
relies on WINS resolution. I have fixed this problem before by adding host file entries
on both machines pointing to the other machine. I can’t guarantee that this will work
in all cases. Both of those machines are no longer under my control.</li></ul></li>
          <li>
Imaged Servers 
<ul><li>
The most recent, and most blogged about problem is surprisingly caused by two machines
created from the same image. Cloning or imaging servers is quite common. Building
a server from scratch is not a fun activity, so we build one, create an image, and
put that image on every server we want to build after that. Once again, MSDTC is standing
in our way because of the way it detects the sending and receiving application’s unique
identifier. Each machine has a GUID in the registry that identifies it uniquely as
a participant in an MSDTC transaction. Imaged machines have the same GUID. I’ll talk
about the detection and resolution of this for the remainder of this post.</li></ul></li>
        </ol>
        <p>
Running DtcPing.exe between the two machines will actually tell you that the machines
are using the same GUID. Output window text from DtcPing shown below.
</p>
        <blockquote>
          <p>
            <font face="Consolas" size="2">DTCping log file: C:\DTC Ping\THRESHER4160.log<br />
Firewall Port Settings:<br />
Port:5150-5250<br />
RPC server is ready<br />
Please Start Partner DTCping before pinging<br /><font color="#ff0000"><strong>WARNING:the CID values for both test machines are the
same</strong><br /></font>Please send following LOG to Microsoft for analysis:<br />
Partner LOG: SCORPION6128.log<br />
My LOG: THRESHER4160.log</font>
          </p>
        </blockquote>
        <p>
Tucked away in the last step of a Microsoft Knowledge Base article titled <a href="http://support.microsoft.com/kb/306843" target="_blank">"How
to troubleshoot MS DTC firewall issues"</a> is a reference to this problem. Use regedit.exe
to look at the registry on both machines. Locate the HKEY_CLASSES_ROOT\CID key in
the registry. 
</p>
        <p>
          <a href="http://scott.klueppel.net/content/binary/Theflowedtransactioncouldnotbeunmarshal_124C3/CID.png">
            <img title="Find your MSDTC CID in the registry" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="371" alt="Find your MSDTC CID in the registry" src="http://scott.klueppel.net/content/binary/Theflowedtransactioncouldnotbeunmarshal_124C3/CID_thumb.png" width="771" border="0" />
          </a>
        </p>
        <p>
Find the CID key that has a description value of “MSDTC”. If they are the same, the
transaction cannot flow. 
</p>
        <p>
          <strong>WARNING:</strong> Back up your registry before making any changes!
</p>
        <p>
          <strong>Solution 1 - Replace the offending CID keys/values on one of the machines: </strong>In
this case, you will need to find all keys/values with GUID 28b81f1c-2afb-4ee2-ad85-5bc62dad1647
in your registry and replace it with a new GUID (using GuidGen). There is likely to
be 3 places this GUID appears. It is also important to note that the offending GUID
appears in the DtcPing log file generated during the ping test.
</p>
        <p>
          <strong>Solution 2 – Use msdtc command line tool to re-install MSDTC: </strong>The
commands are simply:
</p>
        <blockquote>
          <p>
            <font face="consol" size="2">msdtc -uninstall<br />
msdtc -install</font>
          </p>
        </blockquote>
        <p>
After making the registry changes or running the msdtc command line tool, you must
restart your server for the changes to take effect.
</p>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=08cef9e9-c8f3-49a5-bd38-dcb303bb9c52" />
      </body>
      <title>The flowed transaction could not be unmarshaled.</title>
      <guid isPermaLink="false">http://offroadcoder.com/PermaLink,guid,08cef9e9-c8f3-49a5-bd38-dcb303bb9c52.aspx</guid>
      <link>http://offroadcoder.com/2009/01/29/TheFlowedTransactionCouldNotBeUnmarshaled.aspx</link>
      <pubDate>Thu, 29 Jan 2009 02:39:52 GMT</pubDate>
      <description>&lt;div style="width: 550px"&gt;
&lt;p&gt;
“Do not anticipate trouble, or worry about what may never happen. Keep in the sunlight.” 
&lt;p&gt;
&amp;nbsp; 
&lt;p align="right"&gt;
- Benjamin Franklin
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
It’s obvious that Mr. Franklin didn’t have to deal with bad data, bad code, or even
the occasional hiccup. In the real world, there is “trouble” and we need to not only
anticipate that trouble, but also worry about what may never happen. Simply “keeping
in the sunlight” won’t maintain data or application state integrity. In the real world
we need transactions! 
&lt;p&gt;
&amp;nbsp; 
&lt;p&gt;
Since .NET 2.0, we’ve had the privilege of using &lt;em&gt;System.Transactions.TransactionScope&lt;/em&gt; to
manage our transactions with very few headaches. One of the headaches that almost
everyone experiences is MSDTC. One of the oldest and most elusive topics on the web.
There are tons of blog and forum posts directing our fellow developers to check their
firewall settings for every MSDTC problem. The latest MSDTC hiccup I have seen comes
in the beautifully packaged error message: &lt;blockquote&gt; 
&lt;p&gt;
&lt;strong&gt;The flowed transaction could not be unmarshaled. The following exception occurred:
Communication with the underlying transaction manager has failed.&lt;/strong&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
The what could not be what? You can read some &lt;a href="http://msdn.microsoft.com/en-us/library/cc229833(PROT.10).aspx " target="_blank"&gt;MSDN
documentation on the topic&lt;/a&gt; which will probably cause you more pain. If you are
seeing this error message, there’s only a few things that may be wrong. 
&lt;ol&gt;
&lt;li&gt;
MSDTC Settings 
&lt;ul&gt;
&lt;li&gt;
Check the MSDTC settings on the machine that is initiating the transaction. If “Allow
Outbound” is not checked, then it won’t allow the transaction in progress to be flowed
to the next machine in the transaction chain. Check the box and restart MSDTC… it
should work.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;
Un-Trusted Domains 
&lt;ul&gt;
&lt;li&gt;
I have seen this error when you are trying to flow transactions between machines that
are in un-trusted domains. Machines in different domains that do not trust each other
block the antiquated, yet necessary, WINS resolution between the two machines. MSDTC
relies on WINS resolution. I have fixed this problem before by adding host file entries
on both machines pointing to the other machine. I can’t guarantee that this will work
in all cases. Both of those machines are no longer under my control.&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;
Imaged Servers 
&lt;ul&gt;
&lt;li&gt;
The most recent, and most blogged about problem is surprisingly caused by two machines
created from the same image. Cloning or imaging servers is quite common. Building
a server from scratch is not a fun activity, so we build one, create an image, and
put that image on every server we want to build after that. Once again, MSDTC is standing
in our way because of the way it detects the sending and receiving application’s unique
identifier. Each machine has a GUID in the registry that identifies it uniquely as
a participant in an MSDTC transaction. Imaged machines have the same GUID. I’ll talk
about the detection and resolution of this for the remainder of this post.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Running DtcPing.exe between the two machines will actually tell you that the machines
are using the same GUID. Output window text from DtcPing shown below.
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font face="Consolas" size="2"&gt;DTCping log file: C:\DTC Ping\THRESHER4160.log&lt;br&gt;
Firewall Port Settings:&lt;br&gt;
Port:5150-5250&lt;br&gt;
RPC server is ready&lt;br&gt;
Please Start Partner DTCping before pinging&lt;br&gt;
&lt;font color="#ff0000"&gt;&lt;strong&gt;WARNING:the CID values for both test machines are the
same&lt;/strong&gt;
&lt;br&gt;
&lt;/font&gt;Please send following LOG to Microsoft for analysis:&lt;br&gt;
Partner LOG: SCORPION6128.log&lt;br&gt;
My LOG: THRESHER4160.log&lt;/font&gt; 
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Tucked away in the last step of a Microsoft Knowledge Base article titled &lt;a href="http://support.microsoft.com/kb/306843" target="_blank"&gt;"How
to troubleshoot MS DTC firewall issues"&lt;/a&gt; is a reference to this problem. Use regedit.exe
to look at the registry on both machines. Locate the HKEY_CLASSES_ROOT\CID key in
the registry. 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://scott.klueppel.net/content/binary/Theflowedtransactioncouldnotbeunmarshal_124C3/CID.png"&gt;&lt;img title="Find your MSDTC CID in the registry" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="371" alt="Find your MSDTC CID in the registry" src="http://scott.klueppel.net/content/binary/Theflowedtransactioncouldnotbeunmarshal_124C3/CID_thumb.png" width="771" border="0"&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
Find the CID key that has a description value of “MSDTC”. If they are the same, the
transaction cannot flow. 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;WARNING:&lt;/strong&gt; Back up your registry before making any changes!
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Solution 1 - Replace the offending CID keys/values on one of the machines: &lt;/strong&gt;In
this case, you will need to find all keys/values with GUID 28b81f1c-2afb-4ee2-ad85-5bc62dad1647
in your registry and replace it with a new GUID (using GuidGen). There is likely to
be 3 places this GUID appears. It is also important to note that the offending GUID
appears in the DtcPing log file generated during the ping test.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Solution 2 – Use msdtc command line tool to re-install MSDTC: &lt;/strong&gt;The
commands are simply:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font face="consol" size="2"&gt;msdtc -uninstall&lt;br&gt;
msdtc -install&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
After making the registry changes or running the msdtc command line tool, you must
restart your server for the changes to take effect.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=08cef9e9-c8f3-49a5-bd38-dcb303bb9c52" /&gt;</description>
      <comments>http://offroadcoder.com/CommentView,guid,08cef9e9-c8f3-49a5-bd38-dcb303bb9c52.aspx</comments>
      <category>.NET Framework</category>
      <category>MSDTC</category>
      <category>Quotes</category>
      <category>Transactions</category>
      <category>WCF</category>
    </item>
    <item>
      <trackback:ping>http://offroadcoder.com/Trackback.aspx?guid=5aef3f0a-3e66-4e87-8469-0411651d2aba</trackback:ping>
      <pingback:server>http://offroadcoder.com/pingback.aspx</pingback:server>
      <pingback:target>http://offroadcoder.com/PermaLink,guid,5aef3f0a-3e66-4e87-8469-0411651d2aba.aspx</pingback:target>
      <dc:creator>Scott Klueppel</dc:creator>
      <georss:point>30.109017 -81.497099</georss:point>
      <wfw:comment>http://offroadcoder.com/CommentView,guid,5aef3f0a-3e66-4e87-8469-0411651d2aba.aspx</wfw:comment>
      <wfw:commentRss>http://offroadcoder.com/SyndicationService.asmx/GetEntryCommentsRss?guid=5aef3f0a-3e66-4e87-8469-0411651d2aba</wfw:commentRss>
      <slash:comments>8</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Unless you are working on a extremely simple or read-only application, transactions
are a must. Using the System.Transactions namespace is the easiest and most efficient
way to maintain system consistency when dealing with multiple calls or multiple resources.
Although System.Transactions arrived in .NET in the 2005 product, it is still a relatively
unknown part of the framework. System.Transactions was designed by the Indigo team
in preparation for WCF. It is not compatible with Win98 or WinME, but most people
are incompatible with Win98 and WinME so it works out just fine.
</p>
        <p>
Before System.Transactions, we only had access to System.Data.SqlClient.SqlTransaction
or a true SQL transaction using BEGIN/ROLLBACK/COMMIT TRAN. Using SQL transactions,
you are stuck with only being able to update DB records as part of your transaction.
If you wanted to change a cached value in your app in addition to the SQL updates
in the same transaction then you would be out of luck. This also required a lot of
transaction code in your stored procedures, writing stored procedures that can be
called independently or part of transaction made for very messy stored procedures
and often led to multiple stored procedures that served the same purpose.
</p>
        <p>
Using the SqlTransaction class was also messy. The most important restriction is that
you need to have all database calls inside the same SqlConnection. This does not work
well for a well-designed N-tier application. The other problem is that you need to
handle your own non-DB transaction logic inside the same SqlTransaction and conditionally
commit/rollback as necessary. This all tends to lead to several try-catch statements
within one SqlTransaction. Handling the plumbing to manually add each SqlCommand to
the transaction gets old quickly too.
</p>
        <p>
          <strong>Using SqlTransaction</strong>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b string}\cf3  \cf4 connectionString\cf3  = \cf5 ConfigurationManager\cf3 .\cf4 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf4 ConnectionString\cf3 ;\par ??\cf1 {\b using}\cf3  (\cf5 SqlConnection\cf3  \cf4 con\cf3  = \cf1 {\b new}\cf3  \cf5 SqlConnection\cf3 (\cf4 connectionString\cf3 ))\par ??\{\par ??    \cf5 SqlTransaction\cf3  \cf4 tran\cf3  = \cf1 {\b null}\cf3 ;\par ??    \cf1 {\b try}\par ??\cf3     \{\par ??        \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??        \cf4 tran\cf3  = \cf4 con\cf3 .\cf4 BeginTransaction\cf3 ();\par ??        \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??        \{\par ??            \cf4 cmd\cf3 .\cf4 Transaction\cf3  = \cf4 tran\cf3 ;\par ??            \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??            \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??            \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??\par ??        \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??        \{\par ??            \cf4 cmd\cf3 .\cf4 Transaction\cf3  = \cf4 tran\cf3 ;\par ??            \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??            \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 2"\cf3 );\par ??            \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??\par ??        \cf4 tran\cf3 .\cf4 Commit\cf3 ();\par ??    \}\par ??    \cf1 {\b catch}\par ??\cf3     \{\par ??        \cf1 {\b if}\cf3  (\cf4 tran\cf3  != \cf1 {\b null}\cf3 ) \cf4 tran\cf3 .\cf4 Rollback\cf3 ();\par ??    \}\par ??    \cf1 {\b finally}\par ??\cf3     \{\par ??        \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??    \}\par ??\}\par ??}
-->
        </p>
        <div style="OVERFLOW-Y: auto; FONT-SIZE: 9pt; BACKGROUND: #3f3f3f; WIDTH: 761px; COLOR: #dcdccc; FONT-FAMILY: consolas; HEIGHT: 250px">
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   27</span> <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">string</span><span style="COLOR: #dfdfbf">connectionString</span> = <span style="COLOR: #2b91af">ConfigurationManager</span>.<span style="COLOR: #dfdfbf">ConnectionStrings</span>[<span style="COLOR: #c89191">"Testing"</span>].<span style="COLOR: #dfdfbf">ConnectionString</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   28</span> <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlConnection</span><span style="COLOR: #dfdfbf">con</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlConnection</span>(<span style="COLOR: #dfdfbf">connectionString</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   29</span> {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   30</span>     <span style="COLOR: #2b91af">SqlTransaction</span><span style="COLOR: #dfdfbf">tran</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">null</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   31</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">try</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   32</span>     {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   33</span>         <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Open</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   34</span>         <span style="COLOR: #dfdfbf">tran</span> = <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">BeginTransaction</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   35</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlCommand</span><span style="COLOR: #dfdfbf">cmd</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlCommand</span>(<span style="COLOR: #c89191">"usp_ErrorLog_Insert"</span>, <span style="COLOR: #dfdfbf">con</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   36</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   37</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Transaction</span> = <span style="COLOR: #dfdfbf">tran</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   38</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">CommandType</span> = <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">CommandType</span>.<span style="COLOR: #dfdfbf">StoredProcedure</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   39</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"Message"</span>, <span style="COLOR: #c89191">"Testing
1"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   40</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"UserID"</span>, <span style="COLOR: #8acccf">5150</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   41</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">ExecuteNonQuery</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   42</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   43</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   44</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlCommand</span><span style="COLOR: #dfdfbf">cmd</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlCommand</span>(<span style="COLOR: #c89191">"usp_ErrorLog_Insert"</span>, <span style="COLOR: #dfdfbf">con</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   45</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   46</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Transaction</span> = <span style="COLOR: #dfdfbf">tran</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   47</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">CommandType</span> = <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">CommandType</span>.<span style="COLOR: #dfdfbf">StoredProcedure</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   48</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"Message"</span>, <span style="COLOR: #c89191">"Testing
2"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   49</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"UserID"</span>, <span style="COLOR: #8acccf">5150</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   50</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">ExecuteNonQuery</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   51</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   52</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   53</span>         <span style="COLOR: #dfdfbf">tran</span>.<span style="COLOR: #dfdfbf">Commit</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   54</span>     }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   55</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">catch</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   56</span>     {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   57</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">if</span> (<span style="COLOR: #dfdfbf">tran</span> != <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">null</span>) <span style="COLOR: #dfdfbf">tran</span>.<span style="COLOR: #dfdfbf">Rollback</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   58</span>     }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   59</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">finally</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   60</span>     {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   61</span>         <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Close</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   62</span>     }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   63</span> }
</p>
        </div>
        <p>
 
</p>
        <p>
System.Transactions liberated us from the mundane SqlClient code and repetitive try-catches.
simply wrapping your old ADO.NET with a using (TransactionScope) { } is all you need
to do. You will typically add a transactionScope.Complete() statement as the last
line in the TransactionScope using block is really all you need. Any exception thrown
before this point will break out of scope, implicitly aborting the transation. Much
better.
</p>
        <p>
System.Transactions uses the LTM (Lightweight Transaction Manager) when dealing with
single resources or machines. The transaction is automatically promoted to MSDTC (Microsoft
Distributed Transaction Coordinator) when another resource is enlisted in a transaction.
A lot of people struggle with MSDTC because it is difficult to setup, requires special
firewall considerations, and doesn't really work well for smart client applications
since you have to install MSDTC on every client machine.
</p>
        <p>
I'll show one transaction performed three different ways and show what happens with
the LTM and MSDTC for each of them. I will also demonstrate an excellent reason to
migrate to Enterprise Library.
</p>
        <p>
          <strong>1) Executing two ADO.NET SqlCommands in different SqlConnections</strong>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red43\green145\blue175;\red223\green223\blue191;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b using}\cf3  (\cf4 TransactionScope\cf3  \cf5 scope\cf3  = \cf1 {\b new}\cf3  \cf4 TransactionScope\cf3 ())\par ??\{\par ??    \cf1 {\b string}\cf3  \cf5 connectionString\cf3  = \cf4 ConfigurationManager\cf3 .\cf5 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf5 ConnectionString\cf3 ;\par ??    \cf1 {\b using}\cf3  (\cf4 SqlConnection\cf3  \cf5 con\cf3  = \cf1 {\b new}\cf3  \cf4 SqlConnection\cf3 (\cf5 connectionString\cf3 ))\par ??    \cf1 {\b using}\cf3  (\cf4 SqlCommand\cf3  \cf5 cmd\cf3  = \cf1 {\b new}\cf3  \cf4 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf5 con\cf3 ))\par ??    \{\par ??        \cf5 cmd\cf3 .\cf5 CommandType\cf3  = \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 CommandType\cf3 .\cf5 StoredProcedure\cf3 ;\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Open\cf3 ();\par ??            \cf5 cmd\cf3 .\cf5 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf1 {\b using}\cf3  (\cf4 SqlConnection\cf3  \cf5 con\cf3  = \cf1 {\b new}\cf3  \cf4 SqlConnection\cf3 (\cf4 ConfigurationManager\cf3 .\cf5 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf5 ConnectionString\cf3 ))\par ??    \cf1 {\b using}\cf3  (\cf4 SqlCommand\cf3  \cf5 cmd\cf3  = \cf1 {\b new}\cf3  \cf4 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf5 con\cf3 ))\par ??    \{\par ??        \cf5 cmd\cf3 .\cf5 CommandType\cf3  = \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 CommandType\cf3 .\cf5 StoredProcedure\cf3 ;\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 2"\cf3 );\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Open\cf3 ();\par ??            \cf5 cmd\cf3 .\cf5 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf5 scope\cf3 .\cf5 Complete\cf3 ();\par ??\}}
-->
        </p>
        <p>
        </p>
        <p>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red43\green145\blue175;\red223\green223\blue191;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b using}\cf3  (\cf4 TransactionScope\cf3  \cf5 scope\cf3  = \cf1 {\b new}\cf3  \cf4 TransactionScope\cf3 ())\par ??\{\par ??    \cf1 {\b string}\cf3  \cf5 connectionString\cf3  = \cf4 ConfigurationManager\cf3 .\cf5 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf5 ConnectionString\cf3 ;\par ??    \cf1 {\b using}\cf3  (\cf4 SqlConnection\cf3  \cf5 con\cf3  = \cf1 {\b new}\cf3  \cf4 SqlConnection\cf3 (\cf5 connectionString\cf3 ))\par ??    \cf1 {\b using}\cf3  (\cf4 SqlCommand\cf3  \cf5 cmd\cf3  = \cf1 {\b new}\cf3  \cf4 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf5 con\cf3 ))\par ??    \{\par ??        \cf5 cmd\cf3 .\cf5 CommandType\cf3  = \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 CommandType\cf3 .\cf5 StoredProcedure\cf3 ;\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Open\cf3 ();\par ??            \cf5 cmd\cf3 .\cf5 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf1 {\b using}\cf3  (\cf4 SqlConnection\cf3  \cf5 con\cf3  = \cf1 {\b new}\cf3  \cf4 SqlConnection\cf3 (\cf5 connectionString\cf3 ))\par ??    \cf1 {\b using}\cf3  (\cf4 SqlCommand\cf3  \cf5 cmd\cf3  = \cf1 {\b new}\cf3  \cf4 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf5 con\cf3 ))\par ??    \{\par ??        \cf5 cmd\cf3 .\cf5 CommandType\cf3  = \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 CommandType\cf3 .\cf5 StoredProcedure\cf3 ;\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 2"\cf3 );\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Open\cf3 ();\par ??            \cf5 cmd\cf3 .\cf5 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf5 scope\cf3 .\cf5 Complete\cf3 ();\par ??\}}
-->
        </p>
        <div style="OVERFLOW-Y: auto; FONT-SIZE: 9pt; BACKGROUND: #3f3f3f; WIDTH: 764px; COLOR: #dcdccc; FONT-FAMILY: consolas; HEIGHT: 250px">
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  122</span> <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">TransactionScope</span><span style="COLOR: #dfdfbf">scope</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">TransactionScope</span>())
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  123</span> {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  124</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">string</span><span style="COLOR: #dfdfbf">connectionString</span> = <span style="COLOR: #2b91af">ConfigurationManager</span>.<span style="COLOR: #dfdfbf">ConnectionStrings</span>[<span style="COLOR: #c89191">"Testing"</span>].<span style="COLOR: #dfdfbf">ConnectionString</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  125</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlConnection</span><span style="COLOR: #dfdfbf">con</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlConnection</span>(<span style="COLOR: #dfdfbf">connectionString</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  126</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlCommand</span><span style="COLOR: #dfdfbf">cmd</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlCommand</span>(<span style="COLOR: #c89191">"usp_ErrorLog_Insert"</span>, <span style="COLOR: #dfdfbf">con</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  127</span>     {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  128</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">CommandType</span> = <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">CommandType</span>.<span style="COLOR: #dfdfbf">StoredProcedure</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  129</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"Message"</span>, <span style="COLOR: #c89191">"Testing
1"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  130</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"UserID"</span>, <span style="COLOR: #8acccf">5150</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  131</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">try</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  132</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  133</span>             <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Open</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  134</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">ExecuteNonQuery</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  135</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  136</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">finally</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  137</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  138</span>             <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Close</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  139</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  140</span>     }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  141</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  142</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Local
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  143</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">LocalIdentifier</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  144</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Distributed
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  145</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">DistributedIdentifier</span>.<span style="COLOR: #dfdfbf">ToString</span>());
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  146</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  147</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlConnection</span><span style="COLOR: #dfdfbf">con</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlConnection</span>(<span style="COLOR: #dfdfbf">connectionString</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  148</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlCommand</span><span style="COLOR: #dfdfbf">cmd</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlCommand</span>(<span style="COLOR: #c89191">"usp_ErrorLog_Insert"</span>, <span style="COLOR: #dfdfbf">con</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  149</span>     {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  150</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">CommandType</span> = <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">CommandType</span>.<span style="COLOR: #dfdfbf">StoredProcedure</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  151</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"Message"</span>, <span style="COLOR: #c89191">"Testing
2"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  152</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"UserID"</span>, <span style="COLOR: #8acccf">5150</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  153</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">try</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  154</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  155</span>             <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Open</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  156</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">ExecuteNonQuery</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  157</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  158</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">finally</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  159</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  160</span>             <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Close</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  161</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  162</span>     }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  163</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  164</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Local
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  165</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">LocalIdentifier</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  166</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Distributed
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  167</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">DistributedIdentifier</span>.<span style="COLOR: #dfdfbf">ToString</span>());
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  168</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  169</span>     <span style="COLOR: #dfdfbf">scope</span>.<span style="COLOR: #dfdfbf">Complete</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  170</span> }
</p>
        </div>
        <p>
 
</p>
        <p>
This writes the following to the command line:
</p>
        <blockquote>
          <p>
            <font face="Courier New" size="2">
              <strong>Local Transaction ID: e90f47f4-df80-496b-a9c0-0c45b2f452c4:2<br />
Distributed Transaction ID: 00000000-0000-0000-0000-000000000000<br />
Local Transaction ID: e90f47f4-df80-496b-a9c0-0c45b2f452c4:2<br />
Distributed Transaction ID: 1fad8108-ddae-496a-a7da-ce92df175e40</strong>
            </font>
          </p>
        </blockquote>
        <p>
You'll notice that the first command creates a transaction using LTM as indicated
by the <em>Local Transaction ID</em>. After the second command is executed, the transaction
is promoted to DTC as indicated by the <em>Distributed Transaction ID</em>. This is
expected because there are two distinct SqlConnections. Even though the connection
string is the same, TransactionScope treats these ADO.NET objects as unique resources.
</p>
        <p>
This has additional implications when connection pooling comes into play. After I
close the first connection, it is returned to the pool and is available for use. If
this connection is requested for use, it will no longer be available to commit or
abort this transaction, and you will see the dreaded MSDTC error "Communication with
the underlying transaction manager has failed."
</p>
        <p>
        </p>
        <p>
          <strong>2) Executing two ADO.NET SqlCommands in the same SqlConnection</strong>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red220\green220\blue204;\red63\green63\blue63;\red225\green225\blue138;\red43\green145\blue175;\red223\green223\blue191;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2             \cf3 {\b using}\cf1  (\cf4 SqlConnection\cf1  \cf5 con\cf1  = \cf3 {\b new}\cf1  \cf4 SqlConnection\cf1 (\cf4 ConfigurationManager\cf1 .\cf5 ConnectionStrings\cf1 [\cf6 "Testing"\cf1 ].\cf5 ConnectionString\cf1 ))\par ??            \{\par ??                \cf4 SqlTransaction\cf1  \cf5 tran\cf1  = \cf3 {\b null}\cf1 ;\par ??                \cf3 {\b try}\par ??\cf1                 \{\par ??                    \cf5 con\cf1 .\cf5 Open\cf1 ();\par ??                    \cf5 tran\cf1  = \cf5 con\cf1 .\cf5 BeginTransaction\cf1 ();\par ??                    \cf3 {\b using}\cf1  (\cf4 SqlCommand\cf1  \cf5 cmd\cf1  = \cf3 {\b new}\cf1  \cf4 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf5 con\cf1 ))\par ??                    \{\par ??                        \cf5 cmd\cf1 .\cf5 Transaction\cf1  = \cf5 tran\cf1 ;\par ??                        \cf5 cmd\cf1 .\cf5 CommandType\cf1  = \cf5 System\cf1 .\cf5 Data\cf1 .\cf4 CommandType\cf1 .\cf5 StoredProcedure\cf1 ;\par ??                        \cf5 cmd\cf1 .\cf5 Parameters\cf1 .\cf5 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 1"\cf1 );\par ??                        \cf5 cmd\cf1 .\cf5 Parameters\cf1 .\cf5 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                        \cf5 cmd\cf1 .\cf5 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??\par ??                    \cf3 {\b using}\cf1  (\cf4 SqlCommand\cf1  \cf5 cmd\cf1  = \cf3 {\b new}\cf1  \cf4 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf5 con\cf1 ))\par ??                    \{\par ??                        \cf5 cmd\cf1 .\cf5 Transaction\cf1  = \cf5 tran\cf1 ;\par ??                        \cf5 cmd\cf1 .\cf5 CommandType\cf1  = \cf5 System\cf1 .\cf5 Data\cf1 .\cf4 CommandType\cf1 .\cf5 StoredProcedure\cf1 ;\par ??                        \cf5 cmd\cf1 .\cf5 Parameters\cf1 .\cf5 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 2"\cf1 );\par ??                        \cf5 cmd\cf1 .\cf5 Parameters\cf1 .\cf5 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                        \cf5 cmd\cf1 .\cf5 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??\par ??                    \cf5 tran\cf1 .\cf5 Commit\cf1 ();\par ??                \}\par ??                \cf3 {\b catch}\par ??\cf1                 \{\par ??                    \cf3 {\b if}\cf1  (\cf5 tran\cf1  != \cf3 {\b null}\cf1 ) \cf5 tran\cf1 .\cf5 Rollback\cf1 ();\par ??                \}\par ??                \cf3 {\b finally}\par ??\cf1                 \{\par ??                    \cf5 con\cf1 .\cf5 Close\cf1 ();\par ??                \}\par ??            \}}
-->
        </p>
        <p>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red220\green220\blue204;\red63\green63\blue63;\red225\green225\blue138;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2             \cf3 {\b string}\cf1  \cf4 connectionString\cf1  = \cf5 ConfigurationManager\cf1 .\cf4 ConnectionStrings\cf1 [\cf6 "Testing"\cf1 ].\cf4 ConnectionString\cf1 ;\par ??            \cf3 {\b using}\cf1  (\cf5 SqlConnection\cf1  \cf4 con\cf1  = \cf3 {\b new}\cf1  \cf5 SqlConnection\cf1 (\cf4 connectionString\cf1 ))\par ??            \{\par ??                \cf5 SqlTransaction\cf1  \cf4 tran\cf1  = \cf3 {\b null}\cf1 ;\par ??                \cf3 {\b try}\par ??\cf1                 \{\par ??                    \cf4 con\cf1 .\cf4 Open\cf1 ();\par ??                    \cf4 tran\cf1  = \cf4 con\cf1 .\cf4 BeginTransaction\cf1 ();\par ??                    \cf3 {\b using}\cf1  (\cf5 SqlCommand\cf1  \cf4 cmd\cf1  = \cf3 {\b new}\cf1  \cf5 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf4 con\cf1 ))\par ??                    \{\par ??                        \cf4 cmd\cf1 .\cf4 Transaction\cf1  = \cf4 tran\cf1 ;\par ??                        \cf4 cmd\cf1 .\cf4 CommandType\cf1  = \cf4 System\cf1 .\cf4 Data\cf1 .\cf5 CommandType\cf1 .\cf4 StoredProcedure\cf1 ;\par ??                        \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 1"\cf1 );\par ??                        \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                        \cf4 cmd\cf1 .\cf4 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??\par ??                    \cf3 {\b using}\cf1  (\cf5 SqlCommand\cf1  \cf4 cmd\cf1  = \cf3 {\b new}\cf1  \cf5 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf4 con\cf1 ))\par ??                    \{\par ??                        \cf4 cmd\cf1 .\cf4 Transaction\cf1  = \cf4 tran\cf1 ;\par ??                        \cf4 cmd\cf1 .\cf4 CommandType\cf1  = \cf4 System\cf1 .\cf4 Data\cf1 .\cf5 CommandType\cf1 .\cf4 StoredProcedure\cf1 ;\par ??                        \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 2"\cf1 );\par ??                        \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                        \cf4 cmd\cf1 .\cf4 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??\par ??                    \cf4 tran\cf1 .\cf4 Commit\cf1 ();\par ??                \}\par ??                \cf3 {\b catch}\par ??\cf1                 \{\par ??                    \cf3 {\b if}\cf1  (\cf4 tran\cf1  != \cf3 {\b null}\cf1 ) \cf4 tran\cf1 .\cf4 Rollback\cf1 ();\par ??                \}\par ??                \cf3 {\b finally}\par ??\cf1                 \{\par ??                    \cf4 con\cf1 .\cf4 Close\cf1 ();\par ??                \}\par ??            \}}
-->
        </p>
        <p>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red220\green220\blue204;\red63\green63\blue63;\red225\green225\blue138;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2             \cf3 {\b string}\cf1  \cf4 connectionString\cf1  = \cf5 ConfigurationManager\cf1 .\cf4 ConnectionStrings\cf1 [\cf6 "Testing"\cf1 ].\cf4 ConnectionString\cf1 ;\par ??            \cf3 {\b using}\cf1  (\cf5 TransactionScope\cf1  \cf4 scope\cf1  = \cf3 {\b new}\cf1  \cf5 TransactionScope\cf1 ())\par ??            \cf3 {\b using}\cf1  (\cf5 SqlConnection\cf1  \cf4 con\cf1  = \cf3 {\b new}\cf1  \cf5 SqlConnection\cf1 (\cf4 connectionString\cf1 ))\par ??            \{\par ??                \cf3 {\b using}\cf1  (\cf5 SqlCommand\cf1  \cf4 cmd\cf1  = \cf3 {\b new}\cf1  \cf5 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf4 con\cf1 ))\par ??                \{\par ??                    \cf4 cmd\cf1 .\cf4 CommandType\cf1  = \cf4 System\cf1 .\cf4 Data\cf1 .\cf5 CommandType\cf1 .\cf4 StoredProcedure\cf1 ;\par ??                    \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 1"\cf1 );\par ??                    \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                    \cf3 {\b try}\par ??\cf1                     \{\par ??                        \cf4 con\cf1 .\cf4 Open\cf1 ();\par ??                        \cf4 cmd\cf1 .\cf4 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??                    \cf3 {\b finally}\par ??\cf1                     \{\par ??                        \cf4 con\cf1 .\cf4 Close\cf1 ();\par ??                    \}\par ??                \}\par ??\par ??                \cf5 Console\cf1 .\cf4 WriteLine\cf1 (\cf6 "Local Transaction ID: \{0\}"\cf1 , \cf5 Transaction\cf1 .\cf4 Current\cf1 .\cf4 TransactionInformation\cf1 .\cf4 LocalIdentifier\cf1 );\par ??                \cf5 Console\cf1 .\cf4 WriteLine\cf1 (\cf6 "Distributed Transaction ID: \{0\}"\cf1 , \cf5 Transaction\cf1 .\cf4 Current\cf1 .\cf4 TransactionInformation\cf1 .\cf4 DistributedIdentifier\cf1 .\cf4 ToString\cf1 ());\par ??\par ??                \cf3 {\b using}\cf1  (\cf5 SqlCommand\cf1  \cf4 cmd\cf1  = \cf3 {\b new}\cf1  \cf5 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf4 con\cf1 ))\par ??                \{\par ??                    \cf4 cmd\cf1 .\cf4 CommandType\cf1  = \cf4 System\cf1 .\cf4 Data\cf1 .\cf5 CommandType\cf1 .\cf4 StoredProcedure\cf1 ;\par ??                    \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 2"\cf1 );\par ??                    \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                    \cf3 {\b try}\par ??\cf1                     \{\par ??                        \cf4 con\cf1 .\cf4 Open\cf1 ();\par ??                        \cf4 cmd\cf1 .\cf4 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??                    \cf3 {\b finally}\par ??\cf1                     \{\par ??                        \cf4 con\cf1 .\cf4 Close\cf1 ();\par ??                    \}\par ??                \}\par ??\par ??                \cf5 Console\cf1 .\cf4 WriteLine\cf1 (\cf6 "Local Transaction ID: \{0\}"\cf1 , \cf5 Transaction\cf1 .\cf4 Current\cf1 .\cf4 TransactionInformation\cf1 .\cf4 LocalIdentifier\cf1 );\par ??                \cf5 Console\cf1 .\cf4 WriteLine\cf1 (\cf6 "Distributed Transaction ID: \{0\}"\cf1 , \cf5 Transaction\cf1 .\cf4 Current\cf1 .\cf4 TransactionInformation\cf1 .\cf4 DistributedIdentifier\cf1 .\cf4 ToString\cf1 ());\par ??\par ??                \cf4 scope\cf1 .\cf4 Complete\cf1 ();\par ??            \}}
-->
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b string}\cf3  \cf4 connectionString\cf3  = \cf5 ConfigurationManager\cf3 .\cf4 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf4 ConnectionString\cf3 ;\par ??\cf1 {\b using}\cf3  (\cf5 TransactionScope\cf3  \cf4 scope\cf3  = \cf1 {\b new}\cf3  \cf5 TransactionScope\cf3 ())\par ??\cf1 {\b using}\cf3  (\cf5 SqlConnection\cf3  \cf4 con\cf3  = \cf1 {\b new}\cf3  \cf5 SqlConnection\cf3 (\cf4 connectionString\cf3 ))\par ??\{\par ??    \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??    \{\par ??        \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 LocalIdentifier\cf3 );\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 DistributedIdentifier\cf3 .\cf4 ToString\cf3 ());\par ??\par ??    \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??    \{\par ??        \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 2"\cf3 );\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 LocalIdentifier\cf3 );\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 DistributedIdentifier\cf3 .\cf4 ToString\cf3 ());\par ??\par ??    \cf4 scope\cf3 .\cf4 Complete\cf3 ();\par ??\}}
-->
        </p>
        <p>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b string}\cf3  \cf4 connectionString\cf3  = \cf5 ConfigurationManager\cf3 .\cf4 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf4 ConnectionString\cf3 ;\par ??\cf1 {\b using}\cf3  (\cf5 TransactionScope\cf3  \cf4 scope\cf3  = \cf1 {\b new}\cf3  \cf5 TransactionScope\cf3 ())\par ??\cf1 {\b using}\cf3  (\cf5 SqlConnection\cf3  \cf4 con\cf3  = \cf1 {\b new}\cf3  \cf5 SqlConnection\cf3 (\cf4 connectionString\cf3 ))\par ??\{\par ??    \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??    \{\par ??        \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 LocalIdentifier\cf3 );\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 DistributedIdentifier\cf3 .\cf4 ToString\cf3 ());\par ??\par ??    \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??    \{\par ??        \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 2"\cf3 );\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 LocalIdentifier\cf3 );\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 DistributedIdentifier\cf3 .\cf4 ToString\cf3 ());\par ??\par ??    \cf4 scope\cf3 .\cf4 Complete\cf3 ();\par ??\}}
-->
        </p>
        <div style="OVERFLOW-Y: auto; FONT-SIZE: 9pt; BACKGROUND: #3f3f3f; WIDTH: 765px; COLOR: #dcdccc; FONT-FAMILY: consolas; HEIGHT: 250px">
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   69</span> <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">string</span><span style="COLOR: #dfdfbf">connectionString</span> = <span style="COLOR: #2b91af">ConfigurationManager</span>.<span style="COLOR: #dfdfbf">ConnectionStrings</span>[<span style="COLOR: #c89191">"Testing"</span>].<span style="COLOR: #dfdfbf">ConnectionString</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   70</span> <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">TransactionScope</span><span style="COLOR: #dfdfbf">scope</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">TransactionScope</span>())
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   71</span> <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlConnection</span><span style="COLOR: #dfdfbf">con</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlConnection</span>(<span style="COLOR: #dfdfbf">connectionString</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   72</span> {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   73</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlCommand</span><span style="COLOR: #dfdfbf">cmd</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlCommand</span>(<span style="COLOR: #c89191">"usp_ErrorLog_Insert"</span>, <span style="COLOR: #dfdfbf">con</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   74</span>     {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   75</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">CommandType</span> = <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">CommandType</span>.<span style="COLOR: #dfdfbf">StoredProcedure</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   76</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"Message"</span>, <span style="COLOR: #c89191">"Testing
1"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   77</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"UserID"</span>, <span style="COLOR: #8acccf">5150</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   78</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">try</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   79</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   80</span>             <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Open</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   81</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">ExecuteNonQuery</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   82</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   83</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">finally</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   84</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   85</span>             <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Close</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   86</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   87</span>     }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   88</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   89</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Local
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   90</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">LocalIdentifier</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   91</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Distributed
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   92</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">DistributedIdentifier</span>.<span style="COLOR: #dfdfbf">ToString</span>());
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   93</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   94</span>     <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">SqlCommand</span><span style="COLOR: #dfdfbf">cmd</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">SqlCommand</span>(<span style="COLOR: #c89191">"usp_ErrorLog_Insert"</span>, <span style="COLOR: #dfdfbf">con</span>))
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   95</span>     {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   96</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">CommandType</span> = <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">CommandType</span>.<span style="COLOR: #dfdfbf">StoredProcedure</span>;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   97</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"Message"</span>, <span style="COLOR: #c89191">"Testing
2"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   98</span>         <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">Parameters</span>.<span style="COLOR: #dfdfbf">AddWithValue</span>(<span style="COLOR: #c89191">"UserID"</span>, <span style="COLOR: #8acccf">5150</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">   99</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">try</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  100</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  101</span>             <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Open</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  102</span>             <span style="COLOR: #dfdfbf">cmd</span>.<span style="COLOR: #dfdfbf">ExecuteNonQuery</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  103</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  104</span>         <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">finally</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  105</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  106</span>             <span style="COLOR: #dfdfbf">con</span>.<span style="COLOR: #dfdfbf">Close</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  107</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  108</span>     }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  109</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  110</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Local
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  111</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">LocalIdentifier</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  112</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Distributed
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  113</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">DistributedIdentifier</span>.<span style="COLOR: #dfdfbf">ToString</span>());
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  114</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  115</span>     <span style="COLOR: #dfdfbf">scope</span>.<span style="COLOR: #dfdfbf">Complete</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  116</span> }
</p>
        </div>
        <p>
 
</p>
        <p>
This writes the following to the command line:
</p>
        <blockquote>
          <p>
            <font face="Courier New" size="2">
              <strong>Local Transaction ID: e90f47f4-df80-496b-a9c0-0c45b2f452c4:1<br />
Distributed Transaction ID: 00000000-0000-0000-0000-000000000000<br />
Local Transaction ID: e90f47f4-df80-496b-a9c0-0c45b2f452c4:1<br />
Distributed Transaction ID: becac9c9-e15f-4370-9f73-7f369665bed7</strong>
            </font>
          </p>
        </blockquote>
        <p>
        </p>
        <p>
        </p>
        <p>
This is not expected because both commands are part of the same connection. Of course
I am closing the connection to simulate an N-tier app where the data access layer
is maintaining it's own SQL access, opening and closing its connection as it should.
If I did not close the connection, you would not see a <em>Distributed Transaction
ID</em> after the second command.
</p>
        <p>
        </p>
        <p>
          <strong>3) Executing two Enterprise Library commands</strong>
        </p>
        <p>
          <!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red43\green145\blue175;\red223\green223\blue191;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b using}\cf3  (\cf4 TransactionScope\cf3  \cf5 scope\cf3  = \cf1 {\b new}\cf3  \cf4 TransactionScope\cf3 ())\par ??\{\par ??    \cf4 Database\cf3  \cf5 db\cf3  = \cf4 DatabaseFactory\cf3 .\cf5 CreateDatabase\cf3 (\cf6 "Testing"\cf3 );\par ??    \cf4 DbCommand\cf3  \cf5 cmd\cf3  = \cf5 db\cf3 .\cf5 GetStoredProcCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 );\par ??    \cf5 db\cf3 .\cf5 AddInParameter\cf3 (\cf5 cmd\cf3 , \cf6 "Message"\cf3 , \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 DbType\cf3 .\cf5 String\cf3 , \cf6 "Testing 1"\cf3 );\par ??    \cf5 db\cf3 .\cf5 AddInParameter\cf3 (\cf5 cmd\cf3 , \cf6 "UserID"\cf3 , \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 DbType\cf3 .\cf5 Int32\cf3 , \cf7 5150\cf3 );\par ??    \cf5 db\cf3 .\cf5 ExecuteNonQuery\cf3 (\cf5 cmd\cf3 );\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf4 Database\cf3  \cf5 db1\cf3  = \cf4 DatabaseFactory\cf3 .\cf5 CreateDatabase\cf3 (\cf6 "Testing1"\cf3 );\par ??    \cf4 DbCommand\cf3  \cf5 cmd1\cf3  = \cf5 db\cf3 .\cf5 GetStoredProcCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 );\par ??    \cf5 db1\cf3 .\cf5 AddInParameter\cf3 (\cf5 cmd1\cf3 , \cf6 "Message"\cf3 , \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 DbType\cf3 .\cf5 String\cf3 , \cf6 "Testing 2"\cf3 );\par ??    \cf5 db1\cf3 .\cf5 AddInParameter\cf3 (\cf5 cmd1\cf3 , \cf6 "UserID"\cf3 , \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 DbType\cf3 .\cf5 Int32\cf3 , \cf7 5150\cf3 );\par ??    \cf5 db1\cf3 .\cf5 ExecuteNonQuery\cf3 (\cf5 cmd1\cf3 );\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf5 scope\cf3 .\cf5 Complete\cf3 ();\par ??\}}
-->
        </p>
        <div style="OVERFLOW-Y: auto; FONT-SIZE: 9pt; BACKGROUND: #3f3f3f; WIDTH: 761px; COLOR: #dcdccc; FONT-FAMILY: consolas; HEIGHT: 250px">
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  176</span> <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">using</span> (<span style="COLOR: #2b91af">TransactionScope</span><span style="COLOR: #dfdfbf">scope</span> = <span style="FONT-WEIGHT: bold; COLOR: #e1e18a">new</span><span style="COLOR: #2b91af">TransactionScope</span>())
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  177</span> {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  178</span>     <span style="COLOR: #2b91af">Database</span><span style="COLOR: #dfdfbf">db</span> = <span style="COLOR: #2b91af">DatabaseFactory</span>.<span style="COLOR: #dfdfbf">CreateDatabase</span>(<span style="COLOR: #c89191">"Testing"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  179</span>     <span style="COLOR: #2b91af">DbCommand</span><span style="COLOR: #dfdfbf">cmd</span> = <span style="COLOR: #dfdfbf">db</span>.<span style="COLOR: #dfdfbf">GetStoredProcCommand</span>(<span style="COLOR: #c89191">"usp_ErrorLog_Insert"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  180</span>     <span style="COLOR: #dfdfbf">db</span>.<span style="COLOR: #dfdfbf">AddInParameter</span>(<span style="COLOR: #dfdfbf">cmd</span>, <span style="COLOR: #c89191">"Message"</span>, <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">DbType</span>.<span style="COLOR: #dfdfbf">String</span>, <span style="COLOR: #c89191">"Testing
1"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  181</span>     <span style="COLOR: #dfdfbf">db</span>.<span style="COLOR: #dfdfbf">AddInParameter</span>(<span style="COLOR: #dfdfbf">cmd</span>, <span style="COLOR: #c89191">"UserID"</span>, <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">DbType</span>.<span style="COLOR: #dfdfbf">Int32</span>, <span style="COLOR: #8acccf">5150</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  182</span>     <span style="COLOR: #dfdfbf">db</span>.<span style="COLOR: #dfdfbf">ExecuteNonQuery</span>(<span style="COLOR: #dfdfbf">cmd</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  183</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  184</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Local
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  185</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">LocalIdentifier</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  186</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Distributed
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  187</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">DistributedIdentifier</span>.<span style="COLOR: #dfdfbf">ToString</span>());
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  188</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  189</span>     <span style="COLOR: #2b91af">Database</span><span style="COLOR: #dfdfbf">db1</span> = <span style="COLOR: #2b91af">DatabaseFactory</span>.<span style="COLOR: #dfdfbf">CreateDatabase</span>(<span style="COLOR: #c89191">"Testing1"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  190</span>     <span style="COLOR: #2b91af">DbCommand</span><span style="COLOR: #dfdfbf">cmd1</span> = <span style="COLOR: #dfdfbf">db</span>.<span style="COLOR: #dfdfbf">GetStoredProcCommand</span>(<span style="COLOR: #c89191">"usp_ErrorLog_Insert"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  191</span>     <span style="COLOR: #dfdfbf">db1</span>.<span style="COLOR: #dfdfbf">AddInParameter</span>(<span style="COLOR: #dfdfbf">cmd1</span>, <span style="COLOR: #c89191">"Message"</span>, <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">DbType</span>.<span style="COLOR: #dfdfbf">String</span>, <span style="COLOR: #c89191">"Testing
2"</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  192</span>     <span style="COLOR: #dfdfbf">db1</span>.<span style="COLOR: #dfdfbf">AddInParameter</span>(<span style="COLOR: #dfdfbf">cmd1</span>, <span style="COLOR: #c89191">"UserID"</span>, <span style="COLOR: #dfdfbf">System</span>.<span style="COLOR: #dfdfbf">Data</span>.<span style="COLOR: #2b91af">DbType</span>.<span style="COLOR: #dfdfbf">Int32</span>, <span style="COLOR: #8acccf">5150</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  193</span>     <span style="COLOR: #dfdfbf">db1</span>.<span style="COLOR: #dfdfbf">ExecuteNonQuery</span>(<span style="COLOR: #dfdfbf">cmd1</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  194</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  195</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Local
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  196</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">LocalIdentifier</span>);
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  197</span>     <span style="COLOR: #2b91af">Console</span>.<span style="COLOR: #dfdfbf">WriteLine</span>(<span style="COLOR: #c89191">"Distributed
Transaction ID: {0}"</span>, 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  198</span>         <span style="COLOR: #2b91af">Transaction</span>.<span style="COLOR: #dfdfbf">Current</span>.<span style="COLOR: #dfdfbf">TransactionInformation</span>.<span style="COLOR: #dfdfbf">DistributedIdentifier</span>.<span style="COLOR: #dfdfbf">ToString</span>());
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  199</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  200</span>     <span style="COLOR: #dfdfbf">scope</span>.<span style="COLOR: #dfdfbf">Complete</span>();
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #85ac8d">  201</span> }
</p>
        </div>
        <p>
 
</p>
        <p>
This writes the following to the command line:
</p>
        <blockquote>
          <p>
            <font face="Courier New" size="2">
              <strong>Local Transaction ID: 6737b756-2d5b-4eff-902d-15f9ccd5c26f:3<br />
Distributed Transaction ID: 00000000-0000-0000-0000-000000000000<br />
Local Transaction ID: 6737b756-2d5b-4eff-902d-15f9ccd5c26f:3<br />
Distributed Transaction ID: 00000000-0000-0000-0000-000000000000</strong>
            </font>
          </p>
        </blockquote>
        <p>
Whoa! How cool is that? No DTC promotion. Enterprise Library is intelligently deciding
to keep the connection open when it is part of the transaction. This will save a lot
of wasted time as the promotion to DTC adds a noticeable delay. If I wasn't using
Enterprise Library already, I'd switch now.
</p>
        <p>
        </p>
        <p>
Useful links:
</p>
        <ul>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/ms172152.aspx">Implementing an Implicit
Transaction using Transaction Scope</a>
          </li>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/ms730266.aspx">WCF Transactions</a>
          </li>
          <li>
            <a href="http://msdn.microsoft.com/en-us/library/ms973865.aspx">Introducing System.Transactions
in the .NET Framework 2.0</a>
          </li>
        </ul>
        <img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=5aef3f0a-3e66-4e87-8469-0411651d2aba" />
      </body>
      <title>What happens to your transaction with different data access methods</title>
      <guid isPermaLink="false">http://offroadcoder.com/PermaLink,guid,5aef3f0a-3e66-4e87-8469-0411651d2aba.aspx</guid>
      <link>http://offroadcoder.com/2008/12/05/WhatHappensToYourTransactionWithDifferentDataAccessMethods.aspx</link>
      <pubDate>Fri, 05 Dec 2008 02:50:25 GMT</pubDate>
      <description>&lt;p&gt;
Unless you are working on a extremely simple or read-only application, transactions
are a must. Using the System.Transactions namespace is the easiest and most efficient
way to maintain system consistency when dealing with multiple calls or multiple resources.
Although System.Transactions arrived in .NET in the 2005 product, it is still a relatively
unknown part of the framework. System.Transactions was designed by the Indigo team
in preparation for WCF. It is not compatible with Win98 or WinME, but most people
are incompatible with Win98 and WinME so it works out just fine.
&lt;/p&gt;
&lt;p&gt;
Before System.Transactions, we only had access to System.Data.SqlClient.SqlTransaction
or a true SQL transaction using BEGIN/ROLLBACK/COMMIT TRAN. Using SQL transactions,
you are stuck with only being able to update DB records as part of your transaction.
If you wanted to change a cached value in your app in addition to the SQL updates
in the same transaction then you would be out of luck. This also required a lot of
transaction code in your stored procedures, writing stored procedures that can be
called independently or part of transaction made for very messy stored procedures
and often led to multiple stored procedures that served the same purpose.
&lt;/p&gt;
&lt;p&gt;
Using the SqlTransaction class was also messy. The most important restriction is that
you need to have all database calls inside the same SqlConnection. This does not work
well for a well-designed N-tier application. The other problem is that you need to
handle your own non-DB transaction logic inside the same SqlTransaction and conditionally
commit/rollback as necessary. This all tends to lead to several try-catch statements
within one SqlTransaction. Handling the plumbing to manually add each SqlCommand to
the transaction gets old quickly too.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Using SqlTransaction&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b string}\cf3  \cf4 connectionString\cf3  = \cf5 ConfigurationManager\cf3 .\cf4 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf4 ConnectionString\cf3 ;\par ??\cf1 {\b using}\cf3  (\cf5 SqlConnection\cf3  \cf4 con\cf3  = \cf1 {\b new}\cf3  \cf5 SqlConnection\cf3 (\cf4 connectionString\cf3 ))\par ??\{\par ??    \cf5 SqlTransaction\cf3  \cf4 tran\cf3  = \cf1 {\b null}\cf3 ;\par ??    \cf1 {\b try}\par ??\cf3     \{\par ??        \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??        \cf4 tran\cf3  = \cf4 con\cf3 .\cf4 BeginTransaction\cf3 ();\par ??        \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??        \{\par ??            \cf4 cmd\cf3 .\cf4 Transaction\cf3  = \cf4 tran\cf3 ;\par ??            \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??            \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??            \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??\par ??        \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??        \{\par ??            \cf4 cmd\cf3 .\cf4 Transaction\cf3  = \cf4 tran\cf3 ;\par ??            \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??            \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 2"\cf3 );\par ??            \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??\par ??        \cf4 tran\cf3 .\cf4 Commit\cf3 ();\par ??    \}\par ??    \cf1 {\b catch}\par ??\cf3     \{\par ??        \cf1 {\b if}\cf3  (\cf4 tran\cf3  != \cf1 {\b null}\cf3 ) \cf4 tran\cf3 .\cf4 Rollback\cf3 ();\par ??    \}\par ??    \cf1 {\b finally}\par ??\cf3     \{\par ??        \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??    \}\par ??\}\par ??}
--&gt;
&lt;/p&gt;
&lt;div style="OVERFLOW-Y: auto; FONT-SIZE: 9pt; BACKGROUND: #3f3f3f; WIDTH: 761px; COLOR: #dcdccc; FONT-FAMILY: consolas; HEIGHT: 250px"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 27&lt;/span&gt;&amp;nbsp;&lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;string&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;connectionString&lt;/span&gt; = &lt;span style="COLOR: #2b91af"&gt;ConfigurationManager&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ConnectionStrings&lt;/span&gt;[&lt;span style="COLOR: #c89191"&gt;"Testing"&lt;/span&gt;].&lt;span style="COLOR: #dfdfbf"&gt;ConnectionString&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 28&lt;/span&gt;&amp;nbsp;&lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;SqlConnection&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt; = &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SqlConnection&lt;/span&gt;(&lt;span style="COLOR: #dfdfbf"&gt;connectionString&lt;/span&gt;))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 29&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 30&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;SqlTransaction&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;tran&lt;/span&gt; = &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 31&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;try&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 32&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 33&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Open&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 34&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;tran&lt;/span&gt; = &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;BeginTransaction&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 35&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;SqlCommand&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt; = &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SqlCommand&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"usp_ErrorLog_Insert"&lt;/span&gt;, &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 36&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 37&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Transaction&lt;/span&gt; = &lt;span style="COLOR: #dfdfbf"&gt;tran&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 38&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;CommandType&lt;/span&gt; = &lt;span style="COLOR: #dfdfbf"&gt;System&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Data&lt;/span&gt;.&lt;span style="COLOR: #2b91af"&gt;CommandType&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;StoredProcedure&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 39&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Parameters&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;AddWithValue&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Message"&lt;/span&gt;, &lt;span style="COLOR: #c89191"&gt;"Testing
1"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 40&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Parameters&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;AddWithValue&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"UserID"&lt;/span&gt;, &lt;span style="COLOR: #8acccf"&gt;5150&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 41&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ExecuteNonQuery&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 42&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 43&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 44&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;SqlCommand&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt; = &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SqlCommand&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"usp_ErrorLog_Insert"&lt;/span&gt;, &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 45&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 46&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Transaction&lt;/span&gt; = &lt;span style="COLOR: #dfdfbf"&gt;tran&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 47&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;CommandType&lt;/span&gt; = &lt;span style="COLOR: #dfdfbf"&gt;System&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Data&lt;/span&gt;.&lt;span style="COLOR: #2b91af"&gt;CommandType&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;StoredProcedure&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 48&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Parameters&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;AddWithValue&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Message"&lt;/span&gt;, &lt;span style="COLOR: #c89191"&gt;"Testing
2"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 49&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Parameters&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;AddWithValue&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"UserID"&lt;/span&gt;, &lt;span style="COLOR: #8acccf"&gt;5150&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 50&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ExecuteNonQuery&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 51&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 52&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 53&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;tran&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Commit&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 54&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 55&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;catch&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 56&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 57&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;if&lt;/span&gt; (&lt;span style="COLOR: #dfdfbf"&gt;tran&lt;/span&gt; != &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;null&lt;/span&gt;) &lt;span style="COLOR: #dfdfbf"&gt;tran&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Rollback&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 58&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 59&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;finally&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 60&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 61&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Close&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 62&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 63&lt;/span&gt; }
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
System.Transactions liberated us from the mundane SqlClient code and repetitive try-catches.
simply wrapping your old ADO.NET with a using (TransactionScope) { } is all you need
to do. You will typically add a transactionScope.Complete() statement as the last
line in the TransactionScope using block is really all you need. Any exception thrown
before this point will break out of scope, implicitly aborting the transation. Much
better.
&lt;/p&gt;
&lt;p&gt;
System.Transactions uses the LTM (Lightweight Transaction Manager) when dealing with
single resources or machines. The transaction is automatically promoted to MSDTC (Microsoft
Distributed Transaction Coordinator) when another resource is enlisted in a transaction.
A lot of people struggle with MSDTC because it is difficult to setup, requires special
firewall considerations, and doesn't really work well for smart client applications
since you have to install MSDTC on every client machine.
&lt;/p&gt;
&lt;p&gt;
I'll show one transaction performed three different ways and show what happens with
the LTM and MSDTC for each of them. I will also demonstrate an excellent reason to
migrate to Enterprise Library.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;1) Executing two ADO.NET SqlCommands in different SqlConnections&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red43\green145\blue175;\red223\green223\blue191;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b using}\cf3  (\cf4 TransactionScope\cf3  \cf5 scope\cf3  = \cf1 {\b new}\cf3  \cf4 TransactionScope\cf3 ())\par ??\{\par ??    \cf1 {\b string}\cf3  \cf5 connectionString\cf3  = \cf4 ConfigurationManager\cf3 .\cf5 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf5 ConnectionString\cf3 ;\par ??    \cf1 {\b using}\cf3  (\cf4 SqlConnection\cf3  \cf5 con\cf3  = \cf1 {\b new}\cf3  \cf4 SqlConnection\cf3 (\cf5 connectionString\cf3 ))\par ??    \cf1 {\b using}\cf3  (\cf4 SqlCommand\cf3  \cf5 cmd\cf3  = \cf1 {\b new}\cf3  \cf4 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf5 con\cf3 ))\par ??    \{\par ??        \cf5 cmd\cf3 .\cf5 CommandType\cf3  = \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 CommandType\cf3 .\cf5 StoredProcedure\cf3 ;\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Open\cf3 ();\par ??            \cf5 cmd\cf3 .\cf5 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf1 {\b using}\cf3  (\cf4 SqlConnection\cf3  \cf5 con\cf3  = \cf1 {\b new}\cf3  \cf4 SqlConnection\cf3 (\cf4 ConfigurationManager\cf3 .\cf5 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf5 ConnectionString\cf3 ))\par ??    \cf1 {\b using}\cf3  (\cf4 SqlCommand\cf3  \cf5 cmd\cf3  = \cf1 {\b new}\cf3  \cf4 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf5 con\cf3 ))\par ??    \{\par ??        \cf5 cmd\cf3 .\cf5 CommandType\cf3  = \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 CommandType\cf3 .\cf5 StoredProcedure\cf3 ;\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 2"\cf3 );\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Open\cf3 ();\par ??            \cf5 cmd\cf3 .\cf5 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf5 scope\cf3 .\cf5 Complete\cf3 ();\par ??\}}
--&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red43\green145\blue175;\red223\green223\blue191;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b using}\cf3  (\cf4 TransactionScope\cf3  \cf5 scope\cf3  = \cf1 {\b new}\cf3  \cf4 TransactionScope\cf3 ())\par ??\{\par ??    \cf1 {\b string}\cf3  \cf5 connectionString\cf3  = \cf4 ConfigurationManager\cf3 .\cf5 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf5 ConnectionString\cf3 ;\par ??    \cf1 {\b using}\cf3  (\cf4 SqlConnection\cf3  \cf5 con\cf3  = \cf1 {\b new}\cf3  \cf4 SqlConnection\cf3 (\cf5 connectionString\cf3 ))\par ??    \cf1 {\b using}\cf3  (\cf4 SqlCommand\cf3  \cf5 cmd\cf3  = \cf1 {\b new}\cf3  \cf4 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf5 con\cf3 ))\par ??    \{\par ??        \cf5 cmd\cf3 .\cf5 CommandType\cf3  = \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 CommandType\cf3 .\cf5 StoredProcedure\cf3 ;\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Open\cf3 ();\par ??            \cf5 cmd\cf3 .\cf5 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf1 {\b using}\cf3  (\cf4 SqlConnection\cf3  \cf5 con\cf3  = \cf1 {\b new}\cf3  \cf4 SqlConnection\cf3 (\cf5 connectionString\cf3 ))\par ??    \cf1 {\b using}\cf3  (\cf4 SqlCommand\cf3  \cf5 cmd\cf3  = \cf1 {\b new}\cf3  \cf4 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf5 con\cf3 ))\par ??    \{\par ??        \cf5 cmd\cf3 .\cf5 CommandType\cf3  = \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 CommandType\cf3 .\cf5 StoredProcedure\cf3 ;\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 2"\cf3 );\par ??        \cf5 cmd\cf3 .\cf5 Parameters\cf3 .\cf5 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Open\cf3 ();\par ??            \cf5 cmd\cf3 .\cf5 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf5 con\cf3 .\cf5 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf5 scope\cf3 .\cf5 Complete\cf3 ();\par ??\}}
--&gt;
&lt;/p&gt;
&lt;div style="OVERFLOW-Y: auto; FONT-SIZE: 9pt; BACKGROUND: #3f3f3f; WIDTH: 764px; COLOR: #dcdccc; FONT-FAMILY: consolas; HEIGHT: 250px"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 122&lt;/span&gt;&amp;nbsp;&lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;TransactionScope&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;scope&lt;/span&gt; = &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;TransactionScope&lt;/span&gt;())
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 123&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 124&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;string&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;connectionString&lt;/span&gt; = &lt;span style="COLOR: #2b91af"&gt;ConfigurationManager&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ConnectionStrings&lt;/span&gt;[&lt;span style="COLOR: #c89191"&gt;"Testing"&lt;/span&gt;].&lt;span style="COLOR: #dfdfbf"&gt;ConnectionString&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 125&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;SqlConnection&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt; = &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SqlConnection&lt;/span&gt;(&lt;span style="COLOR: #dfdfbf"&gt;connectionString&lt;/span&gt;))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 126&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;SqlCommand&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt; = &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SqlCommand&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"usp_ErrorLog_Insert"&lt;/span&gt;, &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 127&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 128&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;CommandType&lt;/span&gt; = &lt;span style="COLOR: #dfdfbf"&gt;System&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Data&lt;/span&gt;.&lt;span style="COLOR: #2b91af"&gt;CommandType&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;StoredProcedure&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 129&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Parameters&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;AddWithValue&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Message"&lt;/span&gt;, &lt;span style="COLOR: #c89191"&gt;"Testing
1"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 130&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Parameters&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;AddWithValue&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"UserID"&lt;/span&gt;, &lt;span style="COLOR: #8acccf"&gt;5150&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 131&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;try&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 132&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 133&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Open&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 134&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ExecuteNonQuery&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 135&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 136&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;finally&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 137&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 138&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Close&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 139&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 140&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 141&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 142&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Console&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;WriteLine&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Local
Transaction ID: {0}"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 143&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Transaction&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Current&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;TransactionInformation&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;LocalIdentifier&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 144&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Console&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;WriteLine&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Distributed
Transaction ID: {0}"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 145&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Transaction&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Current&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;TransactionInformation&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;DistributedIdentifier&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ToString&lt;/span&gt;());
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 146&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 147&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;SqlConnection&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt; = &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SqlConnection&lt;/span&gt;(&lt;span style="COLOR: #dfdfbf"&gt;connectionString&lt;/span&gt;))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 148&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;SqlCommand&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt; = &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SqlCommand&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"usp_ErrorLog_Insert"&lt;/span&gt;, &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 149&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 150&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;CommandType&lt;/span&gt; = &lt;span style="COLOR: #dfdfbf"&gt;System&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Data&lt;/span&gt;.&lt;span style="COLOR: #2b91af"&gt;CommandType&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;StoredProcedure&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 151&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Parameters&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;AddWithValue&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Message"&lt;/span&gt;, &lt;span style="COLOR: #c89191"&gt;"Testing
2"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 152&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Parameters&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;AddWithValue&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"UserID"&lt;/span&gt;, &lt;span style="COLOR: #8acccf"&gt;5150&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 153&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;try&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 154&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 155&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Open&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 156&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ExecuteNonQuery&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 157&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 158&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;finally&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 159&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 160&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Close&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 161&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 162&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 163&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 164&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Console&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;WriteLine&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Local
Transaction ID: {0}"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 165&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Transaction&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Current&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;TransactionInformation&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;LocalIdentifier&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 166&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Console&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;WriteLine&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Distributed
Transaction ID: {0}"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 167&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Transaction&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Current&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;TransactionInformation&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;DistributedIdentifier&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ToString&lt;/span&gt;());
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 168&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 169&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;scope&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Complete&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 170&lt;/span&gt; }
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
This writes the following to the command line:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font face="Courier New" size=2&gt;&lt;strong&gt;Local Transaction ID: e90f47f4-df80-496b-a9c0-0c45b2f452c4:2&lt;br&gt;
Distributed Transaction ID: 00000000-0000-0000-0000-000000000000&lt;br&gt;
Local Transaction ID: e90f47f4-df80-496b-a9c0-0c45b2f452c4:2&lt;br&gt;
Distributed Transaction ID: 1fad8108-ddae-496a-a7da-ce92df175e40&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
You'll notice that the first command creates a transaction using LTM as indicated
by the &lt;em&gt;Local Transaction ID&lt;/em&gt;. After the second command is executed, the transaction
is promoted to DTC as indicated by the &lt;em&gt;Distributed Transaction ID&lt;/em&gt;. This is
expected because there are two distinct SqlConnections. Even though the connection
string is the same, TransactionScope treats these ADO.NET objects as unique resources.
&lt;/p&gt;
&lt;p&gt;
This has additional implications when connection pooling comes into play. After I
close the first connection, it is returned to the pool and is available for use. If
this connection is requested for use, it will no longer be available to commit or
abort this transaction, and you will see the dreaded MSDTC error "Communication with
the underlying transaction manager has failed."
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;2) Executing two ADO.NET SqlCommands in the same SqlConnection&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red220\green220\blue204;\red63\green63\blue63;\red225\green225\blue138;\red43\green145\blue175;\red223\green223\blue191;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2             \cf3 {\b using}\cf1  (\cf4 SqlConnection\cf1  \cf5 con\cf1  = \cf3 {\b new}\cf1  \cf4 SqlConnection\cf1 (\cf4 ConfigurationManager\cf1 .\cf5 ConnectionStrings\cf1 [\cf6 "Testing"\cf1 ].\cf5 ConnectionString\cf1 ))\par ??            \{\par ??                \cf4 SqlTransaction\cf1  \cf5 tran\cf1  = \cf3 {\b null}\cf1 ;\par ??                \cf3 {\b try}\par ??\cf1                 \{\par ??                    \cf5 con\cf1 .\cf5 Open\cf1 ();\par ??                    \cf5 tran\cf1  = \cf5 con\cf1 .\cf5 BeginTransaction\cf1 ();\par ??                    \cf3 {\b using}\cf1  (\cf4 SqlCommand\cf1  \cf5 cmd\cf1  = \cf3 {\b new}\cf1  \cf4 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf5 con\cf1 ))\par ??                    \{\par ??                        \cf5 cmd\cf1 .\cf5 Transaction\cf1  = \cf5 tran\cf1 ;\par ??                        \cf5 cmd\cf1 .\cf5 CommandType\cf1  = \cf5 System\cf1 .\cf5 Data\cf1 .\cf4 CommandType\cf1 .\cf5 StoredProcedure\cf1 ;\par ??                        \cf5 cmd\cf1 .\cf5 Parameters\cf1 .\cf5 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 1"\cf1 );\par ??                        \cf5 cmd\cf1 .\cf5 Parameters\cf1 .\cf5 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                        \cf5 cmd\cf1 .\cf5 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??\par ??                    \cf3 {\b using}\cf1  (\cf4 SqlCommand\cf1  \cf5 cmd\cf1  = \cf3 {\b new}\cf1  \cf4 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf5 con\cf1 ))\par ??                    \{\par ??                        \cf5 cmd\cf1 .\cf5 Transaction\cf1  = \cf5 tran\cf1 ;\par ??                        \cf5 cmd\cf1 .\cf5 CommandType\cf1  = \cf5 System\cf1 .\cf5 Data\cf1 .\cf4 CommandType\cf1 .\cf5 StoredProcedure\cf1 ;\par ??                        \cf5 cmd\cf1 .\cf5 Parameters\cf1 .\cf5 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 2"\cf1 );\par ??                        \cf5 cmd\cf1 .\cf5 Parameters\cf1 .\cf5 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                        \cf5 cmd\cf1 .\cf5 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??\par ??                    \cf5 tran\cf1 .\cf5 Commit\cf1 ();\par ??                \}\par ??                \cf3 {\b catch}\par ??\cf1                 \{\par ??                    \cf3 {\b if}\cf1  (\cf5 tran\cf1  != \cf3 {\b null}\cf1 ) \cf5 tran\cf1 .\cf5 Rollback\cf1 ();\par ??                \}\par ??                \cf3 {\b finally}\par ??\cf1                 \{\par ??                    \cf5 con\cf1 .\cf5 Close\cf1 ();\par ??                \}\par ??            \}}
--&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red220\green220\blue204;\red63\green63\blue63;\red225\green225\blue138;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2             \cf3 {\b string}\cf1  \cf4 connectionString\cf1  = \cf5 ConfigurationManager\cf1 .\cf4 ConnectionStrings\cf1 [\cf6 "Testing"\cf1 ].\cf4 ConnectionString\cf1 ;\par ??            \cf3 {\b using}\cf1  (\cf5 SqlConnection\cf1  \cf4 con\cf1  = \cf3 {\b new}\cf1  \cf5 SqlConnection\cf1 (\cf4 connectionString\cf1 ))\par ??            \{\par ??                \cf5 SqlTransaction\cf1  \cf4 tran\cf1  = \cf3 {\b null}\cf1 ;\par ??                \cf3 {\b try}\par ??\cf1                 \{\par ??                    \cf4 con\cf1 .\cf4 Open\cf1 ();\par ??                    \cf4 tran\cf1  = \cf4 con\cf1 .\cf4 BeginTransaction\cf1 ();\par ??                    \cf3 {\b using}\cf1  (\cf5 SqlCommand\cf1  \cf4 cmd\cf1  = \cf3 {\b new}\cf1  \cf5 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf4 con\cf1 ))\par ??                    \{\par ??                        \cf4 cmd\cf1 .\cf4 Transaction\cf1  = \cf4 tran\cf1 ;\par ??                        \cf4 cmd\cf1 .\cf4 CommandType\cf1  = \cf4 System\cf1 .\cf4 Data\cf1 .\cf5 CommandType\cf1 .\cf4 StoredProcedure\cf1 ;\par ??                        \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 1"\cf1 );\par ??                        \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                        \cf4 cmd\cf1 .\cf4 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??\par ??                    \cf3 {\b using}\cf1  (\cf5 SqlCommand\cf1  \cf4 cmd\cf1  = \cf3 {\b new}\cf1  \cf5 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf4 con\cf1 ))\par ??                    \{\par ??                        \cf4 cmd\cf1 .\cf4 Transaction\cf1  = \cf4 tran\cf1 ;\par ??                        \cf4 cmd\cf1 .\cf4 CommandType\cf1  = \cf4 System\cf1 .\cf4 Data\cf1 .\cf5 CommandType\cf1 .\cf4 StoredProcedure\cf1 ;\par ??                        \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 2"\cf1 );\par ??                        \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                        \cf4 cmd\cf1 .\cf4 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??\par ??                    \cf4 tran\cf1 .\cf4 Commit\cf1 ();\par ??                \}\par ??                \cf3 {\b catch}\par ??\cf1                 \{\par ??                    \cf3 {\b if}\cf1  (\cf4 tran\cf1  != \cf3 {\b null}\cf1 ) \cf4 tran\cf1 .\cf4 Rollback\cf1 ();\par ??                \}\par ??                \cf3 {\b finally}\par ??\cf1                 \{\par ??                    \cf4 con\cf1 .\cf4 Close\cf1 ();\par ??                \}\par ??            \}}
--&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red220\green220\blue204;\red63\green63\blue63;\red225\green225\blue138;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2             \cf3 {\b string}\cf1  \cf4 connectionString\cf1  = \cf5 ConfigurationManager\cf1 .\cf4 ConnectionStrings\cf1 [\cf6 "Testing"\cf1 ].\cf4 ConnectionString\cf1 ;\par ??            \cf3 {\b using}\cf1  (\cf5 TransactionScope\cf1  \cf4 scope\cf1  = \cf3 {\b new}\cf1  \cf5 TransactionScope\cf1 ())\par ??            \cf3 {\b using}\cf1  (\cf5 SqlConnection\cf1  \cf4 con\cf1  = \cf3 {\b new}\cf1  \cf5 SqlConnection\cf1 (\cf4 connectionString\cf1 ))\par ??            \{\par ??                \cf3 {\b using}\cf1  (\cf5 SqlCommand\cf1  \cf4 cmd\cf1  = \cf3 {\b new}\cf1  \cf5 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf4 con\cf1 ))\par ??                \{\par ??                    \cf4 cmd\cf1 .\cf4 CommandType\cf1  = \cf4 System\cf1 .\cf4 Data\cf1 .\cf5 CommandType\cf1 .\cf4 StoredProcedure\cf1 ;\par ??                    \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 1"\cf1 );\par ??                    \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                    \cf3 {\b try}\par ??\cf1                     \{\par ??                        \cf4 con\cf1 .\cf4 Open\cf1 ();\par ??                        \cf4 cmd\cf1 .\cf4 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??                    \cf3 {\b finally}\par ??\cf1                     \{\par ??                        \cf4 con\cf1 .\cf4 Close\cf1 ();\par ??                    \}\par ??                \}\par ??\par ??                \cf5 Console\cf1 .\cf4 WriteLine\cf1 (\cf6 "Local Transaction ID: \{0\}"\cf1 , \cf5 Transaction\cf1 .\cf4 Current\cf1 .\cf4 TransactionInformation\cf1 .\cf4 LocalIdentifier\cf1 );\par ??                \cf5 Console\cf1 .\cf4 WriteLine\cf1 (\cf6 "Distributed Transaction ID: \{0\}"\cf1 , \cf5 Transaction\cf1 .\cf4 Current\cf1 .\cf4 TransactionInformation\cf1 .\cf4 DistributedIdentifier\cf1 .\cf4 ToString\cf1 ());\par ??\par ??                \cf3 {\b using}\cf1  (\cf5 SqlCommand\cf1  \cf4 cmd\cf1  = \cf3 {\b new}\cf1  \cf5 SqlCommand\cf1 (\cf6 "usp_ErrorLog_Insert"\cf1 , \cf4 con\cf1 ))\par ??                \{\par ??                    \cf4 cmd\cf1 .\cf4 CommandType\cf1  = \cf4 System\cf1 .\cf4 Data\cf1 .\cf5 CommandType\cf1 .\cf4 StoredProcedure\cf1 ;\par ??                    \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "Message"\cf1 , \cf6 "Testing 2"\cf1 );\par ??                    \cf4 cmd\cf1 .\cf4 Parameters\cf1 .\cf4 AddWithValue\cf1 (\cf6 "UserID"\cf1 , \cf7 5150\cf1 );\par ??                    \cf3 {\b try}\par ??\cf1                     \{\par ??                        \cf4 con\cf1 .\cf4 Open\cf1 ();\par ??                        \cf4 cmd\cf1 .\cf4 ExecuteNonQuery\cf1 ();\par ??                    \}\par ??                    \cf3 {\b finally}\par ??\cf1                     \{\par ??                        \cf4 con\cf1 .\cf4 Close\cf1 ();\par ??                    \}\par ??                \}\par ??\par ??                \cf5 Console\cf1 .\cf4 WriteLine\cf1 (\cf6 "Local Transaction ID: \{0\}"\cf1 , \cf5 Transaction\cf1 .\cf4 Current\cf1 .\cf4 TransactionInformation\cf1 .\cf4 LocalIdentifier\cf1 );\par ??                \cf5 Console\cf1 .\cf4 WriteLine\cf1 (\cf6 "Distributed Transaction ID: \{0\}"\cf1 , \cf5 Transaction\cf1 .\cf4 Current\cf1 .\cf4 TransactionInformation\cf1 .\cf4 DistributedIdentifier\cf1 .\cf4 ToString\cf1 ());\par ??\par ??                \cf4 scope\cf1 .\cf4 Complete\cf1 ();\par ??            \}}
--&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b string}\cf3  \cf4 connectionString\cf3  = \cf5 ConfigurationManager\cf3 .\cf4 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf4 ConnectionString\cf3 ;\par ??\cf1 {\b using}\cf3  (\cf5 TransactionScope\cf3  \cf4 scope\cf3  = \cf1 {\b new}\cf3  \cf5 TransactionScope\cf3 ())\par ??\cf1 {\b using}\cf3  (\cf5 SqlConnection\cf3  \cf4 con\cf3  = \cf1 {\b new}\cf3  \cf5 SqlConnection\cf3 (\cf4 connectionString\cf3 ))\par ??\{\par ??    \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??    \{\par ??        \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 LocalIdentifier\cf3 );\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 DistributedIdentifier\cf3 .\cf4 ToString\cf3 ());\par ??\par ??    \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??    \{\par ??        \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 2"\cf3 );\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 LocalIdentifier\cf3 );\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 DistributedIdentifier\cf3 .\cf4 ToString\cf3 ());\par ??\par ??    \cf4 scope\cf3 .\cf4 Complete\cf3 ();\par ??\}}
--&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red223\green223\blue191;\red43\green145\blue175;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b string}\cf3  \cf4 connectionString\cf3  = \cf5 ConfigurationManager\cf3 .\cf4 ConnectionStrings\cf3 [\cf6 "Testing"\cf3 ].\cf4 ConnectionString\cf3 ;\par ??\cf1 {\b using}\cf3  (\cf5 TransactionScope\cf3  \cf4 scope\cf3  = \cf1 {\b new}\cf3  \cf5 TransactionScope\cf3 ())\par ??\cf1 {\b using}\cf3  (\cf5 SqlConnection\cf3  \cf4 con\cf3  = \cf1 {\b new}\cf3  \cf5 SqlConnection\cf3 (\cf4 connectionString\cf3 ))\par ??\{\par ??    \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??    \{\par ??        \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 1"\cf3 );\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 LocalIdentifier\cf3 );\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 DistributedIdentifier\cf3 .\cf4 ToString\cf3 ());\par ??\par ??    \cf1 {\b using}\cf3  (\cf5 SqlCommand\cf3  \cf4 cmd\cf3  = \cf1 {\b new}\cf3  \cf5 SqlCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 , \cf4 con\cf3 ))\par ??    \{\par ??        \cf4 cmd\cf3 .\cf4 CommandType\cf3  = \cf4 System\cf3 .\cf4 Data\cf3 .\cf5 CommandType\cf3 .\cf4 StoredProcedure\cf3 ;\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "Message"\cf3 , \cf6 "Testing 2"\cf3 );\par ??        \cf4 cmd\cf3 .\cf4 Parameters\cf3 .\cf4 AddWithValue\cf3 (\cf6 "UserID"\cf3 , \cf7 5150\cf3 );\par ??        \cf1 {\b try}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Open\cf3 ();\par ??            \cf4 cmd\cf3 .\cf4 ExecuteNonQuery\cf3 ();\par ??        \}\par ??        \cf1 {\b finally}\par ??\cf3         \{\par ??            \cf4 con\cf3 .\cf4 Close\cf3 ();\par ??        \}\par ??    \}\par ??\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 LocalIdentifier\cf3 );\par ??    \cf5 Console\cf3 .\cf4 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf5 Transaction\cf3 .\cf4 Current\cf3 .\cf4 TransactionInformation\cf3 .\cf4 DistributedIdentifier\cf3 .\cf4 ToString\cf3 ());\par ??\par ??    \cf4 scope\cf3 .\cf4 Complete\cf3 ();\par ??\}}
--&gt;
&lt;/p&gt;
&lt;div style="OVERFLOW-Y: auto; FONT-SIZE: 9pt; BACKGROUND: #3f3f3f; WIDTH: 765px; COLOR: #dcdccc; FONT-FAMILY: consolas; HEIGHT: 250px"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 69&lt;/span&gt;&amp;nbsp;&lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;string&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;connectionString&lt;/span&gt; = &lt;span style="COLOR: #2b91af"&gt;ConfigurationManager&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ConnectionStrings&lt;/span&gt;[&lt;span style="COLOR: #c89191"&gt;"Testing"&lt;/span&gt;].&lt;span style="COLOR: #dfdfbf"&gt;ConnectionString&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 70&lt;/span&gt;&amp;nbsp;&lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;TransactionScope&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;scope&lt;/span&gt; = &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;TransactionScope&lt;/span&gt;())
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 71&lt;/span&gt;&amp;nbsp;&lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;SqlConnection&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt; = &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SqlConnection&lt;/span&gt;(&lt;span style="COLOR: #dfdfbf"&gt;connectionString&lt;/span&gt;))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 72&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 73&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;SqlCommand&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt; = &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SqlCommand&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"usp_ErrorLog_Insert"&lt;/span&gt;, &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 74&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 75&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;CommandType&lt;/span&gt; = &lt;span style="COLOR: #dfdfbf"&gt;System&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Data&lt;/span&gt;.&lt;span style="COLOR: #2b91af"&gt;CommandType&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;StoredProcedure&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 76&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Parameters&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;AddWithValue&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Message"&lt;/span&gt;, &lt;span style="COLOR: #c89191"&gt;"Testing
1"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 77&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Parameters&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;AddWithValue&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"UserID"&lt;/span&gt;, &lt;span style="COLOR: #8acccf"&gt;5150&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 78&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;try&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 79&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 80&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Open&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 81&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ExecuteNonQuery&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 82&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 83&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;finally&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 84&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 85&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Close&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 86&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 87&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 88&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 89&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Console&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;WriteLine&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Local
Transaction ID: {0}"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 90&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Transaction&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Current&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;TransactionInformation&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;LocalIdentifier&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 91&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Console&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;WriteLine&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Distributed
Transaction ID: {0}"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 92&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Transaction&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Current&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;TransactionInformation&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;DistributedIdentifier&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ToString&lt;/span&gt;());
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 93&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 94&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;SqlCommand&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt; = &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;SqlCommand&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"usp_ErrorLog_Insert"&lt;/span&gt;, &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 95&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 96&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;CommandType&lt;/span&gt; = &lt;span style="COLOR: #dfdfbf"&gt;System&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Data&lt;/span&gt;.&lt;span style="COLOR: #2b91af"&gt;CommandType&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;StoredProcedure&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 97&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Parameters&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;AddWithValue&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Message"&lt;/span&gt;, &lt;span style="COLOR: #c89191"&gt;"Testing
2"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 98&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Parameters&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;AddWithValue&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"UserID"&lt;/span&gt;, &lt;span style="COLOR: #8acccf"&gt;5150&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp;&amp;nbsp; 99&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;try&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 100&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 101&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Open&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 102&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ExecuteNonQuery&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 103&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 104&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;finally&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 105&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 106&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;con&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Close&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 107&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 108&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 109&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 110&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Console&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;WriteLine&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Local
Transaction ID: {0}"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 111&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Transaction&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Current&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;TransactionInformation&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;LocalIdentifier&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 112&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Console&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;WriteLine&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Distributed
Transaction ID: {0}"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 113&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Transaction&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Current&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;TransactionInformation&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;DistributedIdentifier&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ToString&lt;/span&gt;());
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 114&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 115&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;scope&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Complete&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 116&lt;/span&gt; }
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
This writes the following to the command line:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font face="Courier New" size=2&gt;&lt;strong&gt;Local Transaction ID: e90f47f4-df80-496b-a9c0-0c45b2f452c4:1&lt;br&gt;
Distributed Transaction ID: 00000000-0000-0000-0000-000000000000&lt;br&gt;
Local Transaction ID: e90f47f4-df80-496b-a9c0-0c45b2f452c4:1&lt;br&gt;
Distributed Transaction ID: becac9c9-e15f-4370-9f73-7f369665bed7&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
This is not expected because both commands are part of the same connection. Of course
I am closing the connection to simulate an N-tier app where the data access layer
is maintaining it's own SQL access, opening and closing its connection as it should.
If I did not close the connection, you would not see a &lt;em&gt;Distributed Transaction
ID&lt;/em&gt; after the second command.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;3) Executing two Enterprise Library commands&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;!--
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red225\green225\blue138;\red63\green63\blue63;\red220\green220\blue204;\red43\green145\blue175;\red223\green223\blue191;\red200\green145\blue145;\red138\green204\blue207;}??\fs18 \cf1\cb2\highlight2 {\b using}\cf3  (\cf4 TransactionScope\cf3  \cf5 scope\cf3  = \cf1 {\b new}\cf3  \cf4 TransactionScope\cf3 ())\par ??\{\par ??    \cf4 Database\cf3  \cf5 db\cf3  = \cf4 DatabaseFactory\cf3 .\cf5 CreateDatabase\cf3 (\cf6 "Testing"\cf3 );\par ??    \cf4 DbCommand\cf3  \cf5 cmd\cf3  = \cf5 db\cf3 .\cf5 GetStoredProcCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 );\par ??    \cf5 db\cf3 .\cf5 AddInParameter\cf3 (\cf5 cmd\cf3 , \cf6 "Message"\cf3 , \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 DbType\cf3 .\cf5 String\cf3 , \cf6 "Testing 1"\cf3 );\par ??    \cf5 db\cf3 .\cf5 AddInParameter\cf3 (\cf5 cmd\cf3 , \cf6 "UserID"\cf3 , \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 DbType\cf3 .\cf5 Int32\cf3 , \cf7 5150\cf3 );\par ??    \cf5 db\cf3 .\cf5 ExecuteNonQuery\cf3 (\cf5 cmd\cf3 );\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf4 Database\cf3  \cf5 db1\cf3  = \cf4 DatabaseFactory\cf3 .\cf5 CreateDatabase\cf3 (\cf6 "Testing1"\cf3 );\par ??    \cf4 DbCommand\cf3  \cf5 cmd1\cf3  = \cf5 db\cf3 .\cf5 GetStoredProcCommand\cf3 (\cf6 "usp_ErrorLog_Insert"\cf3 );\par ??    \cf5 db1\cf3 .\cf5 AddInParameter\cf3 (\cf5 cmd1\cf3 , \cf6 "Message"\cf3 , \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 DbType\cf3 .\cf5 String\cf3 , \cf6 "Testing 2"\cf3 );\par ??    \cf5 db1\cf3 .\cf5 AddInParameter\cf3 (\cf5 cmd1\cf3 , \cf6 "UserID"\cf3 , \cf5 System\cf3 .\cf5 Data\cf3 .\cf4 DbType\cf3 .\cf5 Int32\cf3 , \cf7 5150\cf3 );\par ??    \cf5 db1\cf3 .\cf5 ExecuteNonQuery\cf3 (\cf5 cmd1\cf3 );\par ??\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Local Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 LocalIdentifier\cf3 );\par ??    \cf4 Console\cf3 .\cf5 WriteLine\cf3 (\cf6 "Distributed Transaction ID: \{0\}"\cf3 , \par ??        \cf4 Transaction\cf3 .\cf5 Current\cf3 .\cf5 TransactionInformation\cf3 .\cf5 DistributedIdentifier\cf3 .\cf5 ToString\cf3 ());\par ??\par ??    \cf5 scope\cf3 .\cf5 Complete\cf3 ();\par ??\}}
--&gt;
&lt;/p&gt;
&lt;div style="OVERFLOW-Y: auto; FONT-SIZE: 9pt; BACKGROUND: #3f3f3f; WIDTH: 761px; COLOR: #dcdccc; FONT-FAMILY: consolas; HEIGHT: 250px"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 176&lt;/span&gt;&amp;nbsp;&lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;using&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;TransactionScope&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;scope&lt;/span&gt; = &lt;span style="FONT-WEIGHT: bold; COLOR: #e1e18a"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;TransactionScope&lt;/span&gt;())
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 177&lt;/span&gt; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 178&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Database&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;db&lt;/span&gt; = &lt;span style="COLOR: #2b91af"&gt;DatabaseFactory&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;CreateDatabase&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Testing"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 179&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;DbCommand&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt; = &lt;span style="COLOR: #dfdfbf"&gt;db&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;GetStoredProcCommand&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"usp_ErrorLog_Insert"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 180&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;db&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;AddInParameter&lt;/span&gt;(&lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;, &lt;span style="COLOR: #c89191"&gt;"Message"&lt;/span&gt;, &lt;span style="COLOR: #dfdfbf"&gt;System&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Data&lt;/span&gt;.&lt;span style="COLOR: #2b91af"&gt;DbType&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;String&lt;/span&gt;, &lt;span style="COLOR: #c89191"&gt;"Testing
1"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 181&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;db&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;AddInParameter&lt;/span&gt;(&lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;, &lt;span style="COLOR: #c89191"&gt;"UserID"&lt;/span&gt;, &lt;span style="COLOR: #dfdfbf"&gt;System&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Data&lt;/span&gt;.&lt;span style="COLOR: #2b91af"&gt;DbType&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Int32&lt;/span&gt;, &lt;span style="COLOR: #8acccf"&gt;5150&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 182&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;db&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ExecuteNonQuery&lt;/span&gt;(&lt;span style="COLOR: #dfdfbf"&gt;cmd&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 183&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 184&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Console&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;WriteLine&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Local
Transaction ID: {0}"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 185&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Transaction&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Current&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;TransactionInformation&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;LocalIdentifier&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 186&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Console&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;WriteLine&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Distributed
Transaction ID: {0}"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 187&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Transaction&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Current&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;TransactionInformation&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;DistributedIdentifier&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ToString&lt;/span&gt;());
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 188&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 189&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Database&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;db1&lt;/span&gt; = &lt;span style="COLOR: #2b91af"&gt;DatabaseFactory&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;CreateDatabase&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Testing1"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 190&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;DbCommand&lt;/span&gt; &lt;span style="COLOR: #dfdfbf"&gt;cmd1&lt;/span&gt; = &lt;span style="COLOR: #dfdfbf"&gt;db&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;GetStoredProcCommand&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"usp_ErrorLog_Insert"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 191&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;db1&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;AddInParameter&lt;/span&gt;(&lt;span style="COLOR: #dfdfbf"&gt;cmd1&lt;/span&gt;, &lt;span style="COLOR: #c89191"&gt;"Message"&lt;/span&gt;, &lt;span style="COLOR: #dfdfbf"&gt;System&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Data&lt;/span&gt;.&lt;span style="COLOR: #2b91af"&gt;DbType&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;String&lt;/span&gt;, &lt;span style="COLOR: #c89191"&gt;"Testing
2"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 192&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;db1&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;AddInParameter&lt;/span&gt;(&lt;span style="COLOR: #dfdfbf"&gt;cmd1&lt;/span&gt;, &lt;span style="COLOR: #c89191"&gt;"UserID"&lt;/span&gt;, &lt;span style="COLOR: #dfdfbf"&gt;System&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Data&lt;/span&gt;.&lt;span style="COLOR: #2b91af"&gt;DbType&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Int32&lt;/span&gt;, &lt;span style="COLOR: #8acccf"&gt;5150&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 193&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;db1&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ExecuteNonQuery&lt;/span&gt;(&lt;span style="COLOR: #dfdfbf"&gt;cmd1&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 194&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 195&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Console&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;WriteLine&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Local
Transaction ID: {0}"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 196&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Transaction&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Current&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;TransactionInformation&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;LocalIdentifier&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 197&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Console&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;WriteLine&lt;/span&gt;(&lt;span style="COLOR: #c89191"&gt;"Distributed
Transaction ID: {0}"&lt;/span&gt;, 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 198&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;Transaction&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Current&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;TransactionInformation&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;DistributedIdentifier&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;ToString&lt;/span&gt;());
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 199&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 200&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #dfdfbf"&gt;scope&lt;/span&gt;.&lt;span style="COLOR: #dfdfbf"&gt;Complete&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #85ac8d"&gt;&amp;nbsp; 201&lt;/span&gt; }
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
This writes the following to the command line:
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font face="Courier New" size=2&gt;&lt;strong&gt;Local Transaction ID: 6737b756-2d5b-4eff-902d-15f9ccd5c26f:3&lt;br&gt;
Distributed Transaction ID: 00000000-0000-0000-0000-000000000000&lt;br&gt;
Local Transaction ID: 6737b756-2d5b-4eff-902d-15f9ccd5c26f:3&lt;br&gt;
Distributed Transaction ID: 00000000-0000-0000-0000-000000000000&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Whoa! How cool is that? No DTC promotion. Enterprise Library is intelligently deciding
to keep the connection open when it is part of the transaction. This will save a lot
of wasted time as the promotion to DTC adds a noticeable delay. If I wasn't using
Enterprise Library already, I'd switch now.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Useful links:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/ms172152.aspx"&gt;Implementing an Implicit
Transaction using Transaction Scope&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/ms730266.aspx"&gt;WCF Transactions&lt;/a&gt; 
&lt;li&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/ms973865.aspx"&gt;Introducing System.Transactions
in the .NET Framework 2.0&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;img width="0" height="0" src="http://offroadcoder.com/aggbug.ashx?id=5aef3f0a-3e66-4e87-8469-0411651d2aba" /&gt;</description>
      <comments>http://offroadcoder.com/CommentView,guid,5aef3f0a-3e66-4e87-8469-0411651d2aba.aspx</comments>
      <category>C#</category>
      <category>MSDTC</category>
      <category>SQL</category>
      <category>Transactions</category>
    </item>
  </channel>
</rss>