Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 436
  • Last Modified:

What happens if if No Commit or Rollback called on SQLTransaction??

I have a C# Application which makes use of SqlConnection and SqlCommand objects with a Transaction set by calling BeginTransaction.

Now what happens say if the application is in the middle of Executing the Command and then abnormally ends (power failure, whatever) so without calling Commit (or Rollback).

So the Connection obviously terminates, what happens to the Transaction? Does it auto rollback when a connection terminates?

Your speedy response is appreciated.

Thanks!
0
Mokwaja
Asked:
Mokwaja
1 Solution
 
bevhostCommented:
Surely if it doesn't commit, then it's not a permanent addition.
0
 
dbaSQLCommented:
under normal circumstances, I believe the entire transaction is terminated and a rollback will occur
i'm not certain, but if the application goes down, the tran may remain open as sql is waiting for it to finish, possibly blocking other processes until that happens.  

0
 
dbaSQLCommented:
yes.  the tran will close if you commit, rollback, exit... or the app crashes
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
MokwajaAuthor Commented:
Yes, but what happens to te Transaction? Does SQL Roll it back? What state is it in then if no Commit or Rollback was called from the app?
0
 
MokwajaAuthor Commented:
Ok, thanks for the comments!
0
 
Joel CoehoornDirector of Information TechnologyCommented:
If it's not committed and the connection drops, it's rolled back.

But if you can, you still want to roll it back yourself.  Transactions cause locking and it may take sql server some time to notice a connection was dropped before it can rollback.  That means the locks are held for a little longer, which is bad.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now