Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I am developing a project where I want to implement SQLTransaction. In form_Load Event I create and apply it. and In the SAVE_Click I want to Commit() or to RollBack() the transaction depending on a condition.

But until I close commit or rollback my other Database Commands are not executing and Request get Timeout.

Please help me. I am not getting the problem.
Posted
Updated 2-Jan-12 6:34am
v2

I would rethink the design, you only need to execute the inserts/updates/deletes inside the transaction - so create your transaction inside the SAVE_Click method.

Best regards
Espen Harlinn
 
Share this answer
 
Comments
[no name] 2-Jan-12 11:59am    
My need is little bit different, I need to write the command in Form_Load Only.and need to execute in Save_Click only. If possible please answer my question otherwise ....
Espen Harlinn 2-Jan-12 12:12pm    
On form load you are only pulling information out of the database - and doing that inside a transaction is pointless. It's when you want to alter the information in the database that transactions make sense, as they allow you to group a set of operations together. A transaction guaranties that either all or none of the changes are made to the database.
Sridhar Patnayak 2-Jan-12 12:43pm    
Good answer Espen. 5+
Espen Harlinn 2-Jan-12 12:44pm    
Thank you, Sridhar!
Mehdi Gholam 2-Jan-12 12:07pm    
Agree completely, 5'ed
This is a very bad design.

Transactions should be as short as possible as they take up resources on the RDBM server.

You should absolutely not start on form load and commit/rollback on a button click which could be anything between 10 secs to 10 minutes in between.
 
Share this answer
 
Comments
[no name] 2-Jan-12 12:13pm    
I know this is a bad design but in between begin and commit transaction nothing is working.
Mehdi Gholam 2-Jan-12 12:24pm    
It makes no difference, it could timeout, and it will lock up resources on the server anyway.
Espen Harlinn 2-Jan-12 12:14pm    
Right - 5'ed!
Mehdi Gholam 2-Jan-12 12:23pm    
Thanks
thatraja 2-Jan-12 12:24pm    
I missed your answer(May be I didn't refresh the page), 5!
Agree with both good answers. A very important rule-of-thumb is: Never have user conversations inside a transaction! No questions, no notifications, just pure logic and executions of SQL statements. If you have to ask something from the user, do it before the transaction. If you encounter problems, rollback and then inform the user.

If you need to know that the situation has been unchanged while the user makes modifications, use optimistic locking. Pessimistic locking just isn't suitable for longer periods of time.
 
Share this answer
 
v2
Comments
Mehdi Gholam 2-Jan-12 12:35pm    
5'ed and Happy new year Mika!
Wendelius 2-Jan-12 12:41pm    
Thanks and Happy New Year for you too. [EDIT] Sorry the latter was for Espen :)
Espen Harlinn 2-Jan-12 12:35pm    
5'ed! - I'd go for optimistic locking too - as it avoids a lot of hassle
Wendelius 2-Jan-12 12:41pm    
Thanks. I hope that the mudslide isn't affecting you in any way!
Espen Harlinn 2-Jan-12 12:43pm    
Nope - I live in Bergen - but thanks for the thought :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900