2 phase commit by example

Posted on 2001-06-14
Last Modified: 2008-02-01
Can anyone explain me 2phase commit by small example?
I've two database server base1 and base2.How can i implement 2 phase commit?Pls expalin me with a small live example used in industry..I'm using sql 2000.
Question by:vivekkj
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 6194057
What you want to do?

To phase commit is implemented in MS DTC (Distributed Transaction Coordinator). As a programmer and administrator, you do not have to do it yourself. If you use middle tier transaction logic, the only thing you have to do is to implement transaction in your component.



Expert Comment

ID: 6195487
Just do
Begin distributed Tran
<Sql Statements>

Commit tran

Expert Comment

ID: 6195489
Just do
Begin distributed Tran
<Sql Statements>

Commit tran
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 18

Expert Comment

ID: 6195858
Why do you want a two phase commit?

Basically this is only used where the transaction controller doesn't have close control over all entities involved in the transaction.

The basic idea is that the first phase is 'are we all ready to commit?', second phase 'go ahead and commit?'
Before responding to the first phase the entity is expected to prepare the system so that nothing will hold up the commit.

Accepted Solution

sefa earned 100 total points
ID: 6199744
suppose you have two SQL Servers server_A and server_B
suppose you have two databases server_A.db_1 and server_B.db_2
suppose you have two table server_A.db_1..table_1 and server_B.db_2..table_2

if you want to insert a row into server_A.db_1..table_1 and update a row from server_B.db_2..table_2
in the same transaction you must use distrubted transaction. to do so,
you should place your insert and update sql statements into

insert into server_A.db_1..table_1 values('hello')
update server_B.db_2..table_2 set my_col='hello'
-- or if any error occured then

In this example both insert and update are succesful or not.

to support this feature MS DTC service must be running.

Expert Comment

ID: 6900192
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> You cannot delete a question with comments, special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process for further information, if needed.

Click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.  Anytime you have questions which are LOCKED with a Proposed Answer but does not serve your needs, please reject it and add comments as to why.  In addition, when you do grade the question, if the grade is less than an A, please add a comment as to why.  This helps all involved, as well as future persons who may access this item in the future to seek help.

To view your open questions, please click the following link(s) and keep them all current with updates.

To view your locked questions, please click the following link(s) and evaluate the proposed answer.

------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link

Moderators will finalize this question if still open in 7 days, by either moving this to the PAQ (Previously Asked Questions) at zero points, deleting it or awarding expert(s) when recommendations are made, or an independent determination can be made.  Expert input is always appreciated to determine the fair outcome.
Thank you everyone.
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.

Expert Comment

ID: 6992946
Force-accepted by
CS Moderator

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question