CodeSmith Community
Your Code. Your Way. Faster!

Problem with transaction

Latest post 01-01-2007 8:03 PM by mqlin. 2 replies.
  • 12-05-2006 5:20 AM

    Problem with transaction

    Hi ,

    While using transactions in service layer as follows

    TransactionManager tran = new TransactionManager(DataRepository.ConnectionStrings["XXX"].ConnectionString);

    tran = ConnectionScope.ValidateOrCreateTransaction();

    try{

    Insert 1

    insert 2

    tran.commit();

    }

    catch(exception)

    {tran.rollback();} 

    In this it states that a transaction has not been started.

    if i do use tran.begintranasction after the validateorcreatetranasction it states that the tranasaction already exists.

    As a result I am not able to commit or roll back.

    am i missing any thing in this?

    thanks in advance for any help.

    Filed under:
    • Post Points: 35
  • 12-06-2006 12:51 PM In reply to

    Re: Problem with transaction

    You would something along the lines of:
    TransactionManager tm = null;
    try
    {
        tm = ConnectionScope.ValidateOrCreateTransaction(true);
        // or use ConnectionScope.CreateTransaction() if u prefer
        order.save();
        customer.save();
        tm.Commit();
    }
    catch (Exception ex)
    {
        tm.Rollback();
    }

    You would not create another transaction manager, this is done by the provider.

     


    Robert Hinojosa
    -------------------------------------
    Member of the Codesmith Tools, .netTiers, teams
    http://www.nettiers.com
    -------------------------------------
    Filed under:
    • Post Points: 35
  • 01-01-2007 8:03 PM In reply to

    • mqlin
    • Top 500 Contributor
    • Joined on 02-26-2006
    • Posts 19
    • Points 365

    Re: Problem with transaction

    How do I do a transaction through Service Layer?

     

    • Post Points: 5
Page 1 of 1 (3 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems