Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 441
  • 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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for 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
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.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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