Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
An unexpected exception may occur when a transaction is committed or rolled back after a data source error has occurred
This article was previously published under Q309335
In Microsoft ADO.NET, an exception may occur when a transaction is committed or rolled back.
When you call the
Commit method of a transaction, you may encounter the following exception:
The COMMIT TRANSACTION request has no corresponding BEGIN TRANSACTION.
Likewise, when you call the
Rollback method of a transaction, you may encounter the following exception:
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION.
This behavior can occur if the data source has encountered a severe error, causing it to roll back the transaction immediately, rather than return control to the caller. As a result, no transaction exists when the
Commit or
Rollback method is called, and therefore the exception is thrown.
This behavior is by design.
However, as with any method call that may result in an exception being thrown, it is recommended that you make the method call within a try ... catch block, as shown in the following sample code:
Visual Basic:
Try
myTransaction.Rollback()
Catch e As Exception
'Handle Exception
End Try
C#:
try
{
myTransaction.Rollback();
}
catch (Exception e)
{
//Handle Exception
}
Article ID: 309335 - Last Review: March 10, 2006 - Revision: 3.3
APPLIES TO
- Microsoft ADO.NET (included with the .NET Framework)
- Microsoft .NET Framework 1.1
- Microsoft ADO.NET 2.0
| kberrmsg kbnofix kbprb kbreadme KB309335 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate