How does TransactionScope guarantee data integrity across multiple databases?

Posted by Bas Smit on Stack Overflow See other posts from Stack Overflow or by Bas Smit
Published on 2010-03-08T11:11:03Z Indexed on 2010/03/08 12:06 UTC
Read the original article Hit count: 483

Hey guys,

Can someone tell me the principle of how TransactionScope guarantees data integrity across multiple databases? I imagine it first sends the commands to the databases and then waits for the databases to respond before sending them a message to apply the command sent earlier. However when execution is stopped abruptly when sending those apply messages we could still end up with a database that has applied the command and one that has not. Can anyone shed some light on this?

Edit:

I guess what Im asking is can I rely on TransactionScope to guarantee data integrity when writing to multiple databases in case of a power outage or a sudden shutdown.

Thanks, Bas

Example:

    using(var scope=new TransactionScope())
    {
        using (var context = new FirstEntities())
        {
            context.AddToSomethingSet(new Something());
            context.SaveChanges();
        }

        using (var context = new SecondEntities())
        {
            context.AddToSomethingElseSet(new SomethingElse());
            context.SaveChanges();
        }

        scope.Complete();
    }

© Stack Overflow or respective owner

Related posts about entity-framework

Related posts about transactionscope