This is being cross-posted to nhusers.
I am encountering an extremely frustrating random bug when using
TransactionScope (with Rhino ESB) + NH Transaction. According to
http://tinyurl.com/4fbq94r, this is happening because NH tried to
rollback an already rolledback transaction when the TransactionScope
disposes. This exception gets swallowed up somewhere because I don't
see it in the logs for NH or Rhino ESB. So something does not get
cleaned up properly, and when NH tries to start the next ITransaction
I get this:
NHibernate.TransactionException: Begin failed with SQL exception --->
System.Data.SqlClient.SqlException: New request is not allowed to
start because it should come with valid transaction descriptor.
at System.Data.SqlClient.SqlConnection.OnError(SqlException
exception, Boolean breakConnection)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException
exception, Boolean breakConnection)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()
at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,
SqlCommand cmdHandler, SqlDataReader dataStream,
BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject
stateObj)
at
System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[]
buffer, TransactionManagerRequestType request, String transactionName,
TransactionManagerIsolationLevel isoLevel, Int32 timeout,
SqlInternalTransaction transaction, TdsParserStateObject stateObj,
Boolean isDelegateControlRequest)
at
System.Data.SqlClient.SqlInternalConnectionTds.PropagateTransactionCookie(Byte[]
cookie)
at
System.Data.SqlClient.SqlInternalConnection.EnlistNonNull(Transaction
tx)
at System.Data.SqlClient.SqlInternalConnection.Enlist(Transaction
tx)
at
System.Data.SqlClient.SqlInternalConnectionTds.Activate(Transaction
transaction)
at
System.Data.ProviderBase.DbConnectionInternal.ActivateConnection(Transaction
transaction)
at
System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection
owningObject)
at
System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection
owningConnection)
at
System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection
outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at NHibernate.Connection.DriverConnectionProvider.GetConnection()
in d:\CSharp\NH\nhibernate\src\NHibernate\Connection
\DriverConnectionProvider.cs:line 46
at NHibernate.AdoNet.ConnectionManager.GetConnection() in d:\CSharp
\NH\nhibernate\src\NHibernate\AdoNet\ConnectionManager.cs:line 196
at NHibernate.Impl.SessionImpl.get_Connection() in d:\CSharp\NH
\nhibernate\src\NHibernate\Impl\SessionImpl.cs:line 1601
at NHibernate.Transaction.AdoTransaction.Begin(IsolationLevel
isolationLevel) in d:\CSharp\NH\nhibernate\src\NHibernate\Transaction
\AdoTransaction.cs:line 130
Like most transaction related bugs this happens randomly and so far I
have been unable to reproduce this with a test.
Half of the guidance I have read says to do:
using (var scope = new TransactionScope())
{
using (var session = sessionFactory.OpenSession())
using (session.BeginTransaction())
{
// do stuff
session.Transaction.Commit();
}
scope.Complete();
}
However, looking at Ayende's Alexandria sample (http://tinyurl.com/
4h6mugy) and Udi's nhibernate unit of work (http://tinyurl.com/
4vt9coj) I see no usage of NH transactions. In fact, Udi's code
explicitly avoids starting an NH transaction if an ambient transaction
is present.
To add another wrinkle, I am using two different session factories in
the same TransactionScope.
What is the recommended course of action? I could use implicit
transactions if Transaction.Current != null or I could turn off
Transactions at the bus level.
--
You received this message because you are subscribed to the Google Groups
"Rhino Tools Dev" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rhino-tools-dev?hl=en.