An unexpected exception may occur when a transaction is committed or rolled back after a data source error has occurred (309335)
The information in this article applies to:
- Microsoft ADO.NET (included with the .NET Framework)
- Microsoft .NET Framework
- Microsoft ADO.Net 2.0
This article was previously published under Q309335 SYMPTOMS
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.
CAUSE
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.
RESOLUTIONThis 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
}
Modification Type: | Major | Last Reviewed: | 3/10/2006 |
---|
Keywords: | kberrmsg kbnofix kbprb kbreadme KB309335 |
---|
|