ASP. NET 2.0 Transaction Processing

Source: Internet
Author: User
The system is complicated and multiple tables are updated. Therefore, you need to use transaction processing.
Https://www.microsoft.com/china/msdn/library/webservices/asp.net/dnbdabdasamppet4.mspx? MFR = true

Http://editblog.csdn.net/msdncolumn/archive/2005/02/25/1658.aspx

Best introduction to http://blog.joycode.com/kaneboy/archive/2005/02/15/44356.aspxSystem. Transactions

Http://idior.cnblogs.com/archive/2005/08/15/214300.htmlIn-depth IntroductionSystem. Transactions
Transaction team Wiki
Florin Lazar's blog
Jim Johnson's blog
Angle Saenz-badillos 'blog

Http://www.15seconds.com/issue/040914.htm

Public   Void Transactiontest ()
{
String Connectionstring =   " " ;
Idbconnection connection =   New Sqlconnection (connectionstring );
Connection. open ();
Idbcommand command =   New Sqlcommand ();
Command. Connection = Connection;
Idbtransaction transaction;
Transaction = Connection. begintransaction (); // Enlisting Database
Command. Transaction = Transaction;
Try
{
/**/ /*Interact with database here, then commit the transaction
*/
Transaction. Commit ();
}
Catch
{
Transaction. rollback ();//Abort transaction
}
Finally
{
Connection. Close ();
}
}

What isSystem. Transactions?

System. TransactionsIs the namespace of the transaction control added in the. NET 2.0 Framework. It is a new way to process distributed transactions without the overhead of COM + registration and COM + directory. Note that Microsoft Distributed Transaction Coordinator is used to initialize transactions.

Running status

Synchronous order processingInOrder. insert ()UsageSystem. TransactionsInsert an order and update the inventory. By addingSystem. TransactionREFERENCE The namespace, and wrap the order Insertion Method and inventory reduction method inTransactionscopeWe have implementedOrder. insert ()Method, suchCodeList 1.

List1.RunningSystem. Transactions

Using system; using system. transactions; using petshop. ibllstrategy; namespace petshop. bll {// <summary> // This is a synchronous Implementation of iorderstrategy // by implementing iorderstrategy interface, the developer can // Add a new order insert strategy without re-compiling the whole // BLL. /// </Summary> public class ordersynchronous: iorderstrategy {... /// <summary> /// inserts the order and updates the inventory stock within // a transaction. /// </Summary> /// <Param name = "order"> all information about the order </param> Public void insert (petshop. model. orderinfo order) {using (transactionscope Ts = newtransactionscope (transactionscopeoption. required) {Dal. insert (order); // update the inventory to reflect the current inventory // after the order submission. inventory inventory = new inventory (); inventory. takestock (Order. lineitems); // calling complete commits the transaction. // excluding this call by the end of transactionscope's // scope will rollback the transaction. ts. complete ();}}}}
 
 
 
 
<% @ Page Language = "VB" DEBUG = "true" %>
<% @ Import namespace = "system. Data" %>
<% @ Import namespace = "system. Data. oledb" %>
 
<HTML>
<Body>
 
<H2> original dataset that was read in from the database: </H2>
<Asp: DataGrid id = "showmembersoriginal" runat = "server"/>
<H2> dataset after changes: </H2>
<Asp: DataGrid id = "showmembersworking" runat = "server"/>
 
</Body>
</Html>
 
Objtable. Rows (0). Delete ()
Objtable. Rows (1) ("lastname") = "-newlastname -"
Objtable. Rows (2). Delete ()
Objtable. Rows (3). Delete ()
Objtable. Rows (4) ("contributions") = "9999"
Objtable. Rows. removeat (5)
Objtable. Rows (5) ("firstname") = "-newfirstname -"
 
Dim objvalsarray (2) as object
Objvalsarray (0) = 0
Objvalsarray (1) = "newonefirstname"
Objvalsarray (2) = "newonelastname"
Objtable. Rows. Add (objvalsarray)
 
Dim objtransaction as oledbtransaction
Dim objcommandbuilder as new oledbcommandbuilder (objdataadapter)
Objdataadapter. deletecommand = objcommandbuilder. getdeletecommand ()
Objdataadapter. insertcommand = objcommandbuilder. getinsertcommand ()
Objdataadapter. updatecommand = objcommandbuilder. getupdatecommand ()
Objconnect. open ()
Objtransaction = objconnect. begintransaction ()
 
Objdataadapter. deletecommand. Transaction = objtransaction
Objdataadapter. insertcommand. Transaction = objtransaction
Objdataadapter. updatecommand. Transaction = objtransaction
 
Objdataadapter. Update (objdataset, "themembers ")
 
Showmembersworking. datasource = objtable. defaultview
Showmembersworking. databind ()
 
'Objtransaction. Commit ()
Objtransaction. rollback ()
 
End sub
</SCRIPT>
 
 
 
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.