ASP 101 - Active Server Pages 101 - Web05
The Place ASP Developers Go!

Please visit our partners


Windows Technology Windows Technology
15 Seconds
4GuysFromRolla.com
ASP 101
ASP Wire
VB Forums
VB Wire
WinDrivers.com
internet.commerce internet.commerce
Partners & Affiliates














ASP 101 is an
internet.com site
ASP 101 is an internet.com site
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash




Script Output:

Starting Transaction.

Executing SQL Command:
INSERT INTO [scratch] (text_field, integer_field, date_time_field) VALUES ('Monday', '1', '12/1/2008 1:35:09 PM');

Records Affected: 1

Commiting Transaction.


Run the script again: Commit Transaction or Rollback Transaction


ASP HTML Download            FAQ

ASP.NET Version

Ensuring data integrity is an important consideration when building an application. The data in your database is most likely valuable to your business and steps need to be taken to ensure that changes made to it are executed correctly. This is where transactions come into play.

Transactions are used to ensure that either all or none of the steps involved in an operation are executed. Accounting is a perfect example of why transactions are important. It's often necessary to transfer money from one account to another. In order to do this you need to first debit money from the source account and then credit it to the destination account. Without transactions, if something went wrong while processing the request, we might be left in a situation where the money had already been removed from the source account and not yet credited to the destination. The resulting confusion over the missing money could cause real problems.

Continuing the same example, by placing both the debit and credit operations into a single transaction we ensure that the funds either move to the new account or they do not. In this example, using a transaction eliminates the possibility of "creating" or "destroying" money. If the funds didn't get transferred then we still need to determine the source of the error and fix it, but at least we don't have to try and track down the missing money as well.

By default this page will execute CommitTrans in order to commit the transaction to the database. If you would like to run the script again you can choose whether or not it will commit (CommitTrans) or rollback (RollbackTrans) the transaction by clicking the corresponding links above.

Please note that clicking the above links will run the script again and either commit or rollback the insertion of a new record. It will not affect any records already added to the database including the one shown above which was already processed.

You should also note that I'm not really doing much of anything in the transaction that would require a transaction. I'm doing a simple insert so that you can see that the data does get inserted when the transaction is committed and doesn't get inserted when it is rolled back. In the real world, you'd most likely have at least two operations going on inside the transaction, but I'm just including one in order to keep things as simple as possible.

You can view any data that was committed to the database via our Simple Database sample. It's probably easiest if you use the value of the date_time_field (shown in the SQL statement above) to locate the appropriate record.


Samples

Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

Whitepapers and eBooks

Intel Whitepaper: Comparing Two- and Four-Socket Platforms for Server Virtualization
IBM Solutions Brief: Go Green With IBM System xTM And Intel
HP eBook: Simplifying SQL Server Management
IBM Contest: Are You the Next Superstar? Join the "Search for the XML Superstar" Contest to Find Out
Microsoft PDF: Top 10 Reasons to Move to Server Virtualization with Hyper-V
Microsoft PDF: Six Reasons Why Microsoft's Hyper-V Will Overtake Vmware
Microsoft Step-by-Step Guide: Hyper-V and Failover Clustering
Intel PDF: Quad-Core Impacts More Than the Data Center
Intel PDF: Virtualization Delivers Data Center Efficiency
Go Parallel Article: PDC 2008 in Review
Microsoft PDF: Top 11 Reasons to Upgrade to Windows Server 2008
Avaya Article: Communication-Enabled Mashups: Empowering Both Business Owners and IT
Intel Whitepaper: Building a Real-World Model to Assess Virtualization Platforms
  PDF: Intel Centrino Duo Processor Technology with Intel Core2 Duo Processor
Microsoft Article: Build and Run Virtual Machines with Hyper-V Server 2008
Go Parallel Article: Q&A with a TBB Junkie
IBM Whitepaper: Innovative Collaboration to Advance Your Business
Internet.com eBook: Real Life Rails
IBM eBook: The Pros and Cons of Outsourcing
Internet.com eBook: Best Practices for Developing a Web Site
IBM CXO Whitepaper: The 2008 Global CEO Study "The Enterprise of the Future"
Avaya Article: Call Control XML in Action - A CCXML Auto Attendant
IBM CXO Whitepaper: Unlocking the DNA of the Adaptable Workforce--The Global Human Capital Study 2008
Adobe Acrobat Connect Pro: Web Conferencing and eLearning Whitepapers
HP eBook: Guide to Storage Networking
MORE WHITEPAPERS, EBOOKS, AND ARTICLES