DJ메탈짱™의 Free Style

[C#] Enterprise Library를 이용한 트랜젝션 처리 본문

일(job)/MS(Microsoft)

[C#] Enterprise Library를 이용한 트랜젝션 처리

뽀&쏭 2015. 12. 3. 21:47

[Enterprise Library를 이용한 트랜젝션 처리]

 

public bool TransactionTest()

{

using (DbConnection connection = db.CreateConnection())

        {

               connection.Open();

                DbTransaction transaction = connection.BeginTransaction();

 

                try

                {

                    // first

                    db.ExecuteNonQuery(firstCommand, transaction);

 

                    // second

                    db.ExecuteNonQuery(secondCommand, transaction);

 

                    // commit the transaction

                    transaction.Commit();

                    return true;

                }

                catch

                {

                    // Rollback the transaction

                    transaction.Rollback();

                    throw;

                }

 

                connection.Close();

                return true;

}

}