We can probably offer another event, before we commit the DTC

On Wed, Oct 21, 2009 at 7:26 PM, Vadim Kantorov <[email protected]>wrote:

>
> Keeping in mind this crazy issue:
>
> http://groups.google.ru/group/nhibernate-development/browse_thread/thread/d3b5413d3ddbdfe7
> I tried to use native NH transactions everywhere just in case. I
> thought creating a message module would be a solution.
> Unfortunately, my module doesn't work correctly.
>
> public class NhMessageModule : IMessageModule
>        {
>        readonly ISessionFactory factory;
>
>                public NhMessageModule(ISessionFactory factory)
>                {
>                        this.factory = factory;
>                }
>
>                public void Init(ITransport transport)
>                {
>                        transport.MessageArrived += OpenSession;
>                        transport.MessageProcessingCompleted +=
> DisposeOfSession;
>                }
>
>                public void Stop(ITransport transport)
>                {
>                        transport.MessageArrived -= OpenSession;
>                        transport.MessageProcessingCompleted -=
> DisposeOfSession;
>                }
>
>                private bool OpenSession(CurrentMessageInformation arg)
>                {
>                        var session = factory.OpenSession();
>                        session.BeginTransaction();
>
>                        CurrentSessionContext.Bind(session);
>
>                        return false;
>                }
>
>                private void DisposeOfSession(CurrentMessageInformation
> arg1,
> Exception arg2)
>                {
>
>                        if (CurrentSessionContext.HasBind(factory))
>                        {
>                                var session =
> CurrentSessionContext.Unbind(factory);
>
>                                if (session.Transaction != null &&
> session.Transaction.IsActive)
>                                        session.Transaction.Commit();
>
>                                session.Dispose();
>                        }
>                }
>        }
>
>
> It fails with an SqlException
> Message: The COMMIT TRANSACTION request has no corresponding BEGIN
> TRANSACTION.
> Stack trace:
>   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
> (TdsParserStateObject stateObj)
>   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.ExecuteTransactionYukon
> (TransactionRequest transactionRequest, String transactionName,
> IsolationLevel iso, SqlInternalTransaction internalTransaction,
> Boolean isDelegateControlRequest)
>   at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction
> (TransactionRequest transactionRequest, String name, IsolationLevel
> iso, SqlInternalTransaction internalTransaction, Boolean
> isDelegateControlRequest)
>   at System.Data.SqlClient.SqlInternalTransaction.Commit()
>   at System.Data.SqlClient.SqlTransaction.Commit()
>   at NHibernate.Transaction.AdoTransaction.Commit()
>
> As I found out  it stems from the fact that the distributed
> transaction (in which RSB encloses every message handling) gets
> disposed before the MessageProcessionCompleted event is fired.
>
> Any other way to enclose every message handling into an NH
> transaction? Do you think this RSB behavior should be changed?
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to