Start and Commit Database Transactions

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
kirondedshem
User
Posts: 642

Start and Commit Database Transactions

Post by kirondedshem »

database = postagresql
I want to execute a start transaction before returning true in row_inserting then in row_inserted I want to run a bunch of queries, then i run commit transaction when am sure everything has saved.

The effect i want is everything query i run in between including the one ran by row_inserting to have completed successfully before i run the commit.

I have tried putting Execute("START TRANSACTION"); before returning true in row_inserting but it still commits even without me putting Execute("COMMIT TRANSACTION"); in row_inserted

I know the trandactions work coz I can put START TRANSACTION in pg admin and run some queries and they wont be saved.
I also Use the same approach alot in phpmaker with ew_Execuete("START TRANSACTION") before return true of row_inserting and it works.

So how do i DO it here, not on row_inserting only coz i will have some other queries in custom action which i need to enclose in a transaction as well.


Webmaster
User
Posts: 9425

Post by Webmaster »

  1. ASP.NET Maker generates its own commit and rollback if you are performing master/detail add/edit. Check the generated codes for Connection.BeginTrans() / Connection.CommitTrans() / Connection.RollbackTrans(). So the transaction may already be commited before Row_Inserted.
  2. Execute create a new database connection. If you are not using master/detail add, you may try using the same connection to run your custom SQL, i.e.: Connection.Execute(...)

kirondedshem
User
Posts: 642

Post by kirondedshem »

Thank,
I am running this on a normal add operation so To start a tranaction ive put Ive put

// Row Inserting event
public bool Row_Inserting(Dictionary<string, object> rsold, Dictionary<string, object> rsnew) {
// Enter your code here
// To cancel, set return value to False and error message to CancelMessage

//start an sql transaction
Connection.BeginTrans();

return true;

}

To commit a transaction when am sure ive dine what want, ive put
// Row Inserting event
public bool Row_Inserted(Dictionary<string, object> rsold, Dictionary<string, object> rsnew) {
// Enter your code here
// To cancel, set return value to False and error message to CancelMessage

    //RUNNING MY QUERIES HERE

//start an sql transaction
Connection.CommitTrans();

return true;

}


Post Reply