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!
MokwajaAsked:
Who is Participating?
 
dbaSQLCommented:
yes.  the tran will close if you commit, rollback, exit... or the app crashes
0
 
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.