AspNet.sk     Diskusné fóra     Vitajte v QuickStarts     ASP.NET     Silverlight     Ako môžem...? (en)     Class prehliadač Príklady chcem v ...   
Menu
Skip Navigation Links.

How Do I...? Common Tasks QuickStart Tutorial

How Do I...Use explicit transactions in my application?

If you want to explicitly create a transaction, use the CommittableTransaction class instead of the TransactionScope class. There are important differences between CommittableTransaction objects and TransactionScope objects:

  • Creating a CommittableTransaction does not set the current transaction. This means a transacted resource you might perform an action on will not automatically be part of the current transaction. You will need to manually pass the transaction you created to the transacted resource.
  • When using CommittableTransactions, you must call commit or rollback.
  • Exceptions do not automatically rollback transactions. Rollback must be called manually if a failure occurred when an exception is thrown.

1. In it's simplest form, create a new CommittableTransaction


	Dim tx As New CommittableTransaction()
VB

2. To commit the transaction, call the commit method


	tx.Commit()
VB

3. Or to rollback the transaction, call the rollback method


	tx.Rollback()
VB

Here is a full example:

[This sample can be found at H:\Home\WU_000036_efe47225c86ca62f325a01d8519bc002\Webs\aspnet.sk\quickstarts\QuickStartv20\howto\samples\Transactions\CommittableTx
To build this sample, open the SDK command prompt and navigate to the above path. Build the sample using the build tool msbuild passing the solution file as the first parameter: msbuild mySample.sln. The compiled executable will be found in the sub directory \bin directory.]




Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2005 Microsoft Corporation. All rights reserved.


Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright © 2005 Microsoft Corporation. All rights reserved.
Preklad do slovenského jazyka - Copyright © 2005 - 2007 www.aspnet.sk, www.qsh.sk
Pošlite komentár k tejto stránke
Copyright © 2002 - 2008 Chastia, spol. s r. o., Igor Stanek, Designed by Lacino
Portál je hostovaný na serveroch firmy Quantasoft - www.qsh.sk.