Solved

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

Posted on 2008-06-19
6
421 Views
Last Modified: 2013-11-06
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
Comment
Question by:Mokwaja
6 Comments
 
LVL 19

Expert Comment

by:bevhost
ID: 21821991
Surely if it doesn't commit, then it's not a permanent addition.
0
 
LVL 17

Expert Comment

by:dbaSQL
ID: 21822056
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
 
LVL 17

Accepted Solution

by:
dbaSQL earned 500 total points
ID: 21822071
yes.  the tran will close if you commit, rollback, exit... or the app crashes
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:Mokwaja
ID: 21822081
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
 

Author Comment

by:Mokwaja
ID: 21822099
Ok, thanks for the comments!
0
 
LVL 18

Expert Comment

by:jcoehoorn
ID: 21822129
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question