New Posts New Posts RSS Feed: How to user transactions
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

How to user transactions

 Post Reply Post Reply
Author
vinothvdp View Drop Down
Newbie
Newbie
Avatar

Joined: 21-Sep-2007
Location: India
Posts: 27
Post Options Post Options   Quote vinothvdp Quote  Post ReplyReply Direct Link To This Post Topic: How to user transactions
    Posted: 13-Dec-2008 at 12:23am
Hello sir,
 
How to use begin ,Commit and rollback transactions.can u give me some example.
 
Thank you.
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 18-Dec-2008 at 1:16pm

Here is how you can do two saves in one transaction:.

(1)        You must use Microsoft Distributed Transaction Coordinator (DTC)

(2)        Start a Transaction (e.g., using (TransactionScope scope = new TransactionScope()

(3)        Do the first SaveChanges using a Transactional Save

(4)        Do the second SaveChanges using a Transactional Save

(5)        If both saves are successful, commit the Transaction (e.g., scope.Complete();

Back to Top
vinothvdp View Drop Down
Newbie
Newbie
Avatar

Joined: 21-Sep-2007
Location: India
Posts: 27
Post Options Post Options   Quote vinothvdp Quote  Post ReplyReply Direct Link To This Post Posted: 18-May-2009 at 6:03am

Hi,

i tried below code but i am getting "Save failed - Cannot start more transactions on this session."

could you please assist me.

 

using (TransactionScope scope = new TransactionScope())

{

try

{

SaveOptions mSaveOptions = new SaveOptions();

mSaveOptions.IsTransactional = true;

pm.SaveChanges(mSaveOptions);

scope.Complete();

MessageBox.Show("Sucess");

}

catch (PersistenceManagerSaveException ex)

{

MessageBox.Show(ex.Message.ToString());

}

finally

{

//scope.Dispose();

}

}

 

Thank you,

Vinoth
Back to Top
davidklitzke View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 14-Jun-2007
Posts: 715
Post Options Post Options   Quote davidklitzke Quote  Post ReplyReply Direct Link To This Post Posted: 18-May-2009 at 8:51am
I tried your code on my machine and did not receive this error.
 
This error occurs in certain situations when you have a nested transaction.
 
I suggest searching the Internet for "Cannot start more transactions on this session".  You will find a good number of matches.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down