Transaction Error When First Call IContentManager.Create

Topics: Writing modules
Aug 18, 2011 at 11:18 AM

We have a custom part that we create something like below:

contentManager.Create<CustomPart>("Custom",
                part =>
                {
                    part.TestProperty = "Test property";
                });

This code is in an action method in a custom controller. We are taking IContentManager as a constructor argument to our controller.

 

The first time this method is called after an iisreset/app pool recycle it throws a transaction error. Calling this method subsequent times it works just fine.

The two transaction errors I have recieved so far are:

 

Microsoft Distributed Transaction Coordinator (MS DTC) has stopped this transaction

[SqlException (0x80131904): Microsoft Distributed Transaction Coordinator (MS DTC) has stopped this transaction.]   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +404   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +412   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1363   System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest) +1273   System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest) +611   System.Data.SqlClient.SqlDelegatedTransaction.SinglePhaseCommit(SinglePhaseEnlistment enlistment) +460
[TransactionAbortedException: The transaction has aborted.]   System.Transactions.TransactionStatePromotedAborted.PromotedTransactionOutcome(InternalTransaction tx) +228077   System.Transactions.CommittableTransaction.Commit() +453   System.Transactions.TransactionScope.InternalDispose() +638   System.Transactions.TransactionScope.Dispose() +2492   Orchard.Data.TransactionManager.System.IDisposable.Dispose() in d:\TeamCity\Projects\Orchard-Default\src\Orchard\Data\TransactionManager.cs:47   Autofac.Core.Disposer.Dispose(Boolean disposing) +82   Autofac.Util.Disposable.Dispose() +43   Autofac.Core.Lifetime.LifetimeScope.Dispose(Boolean disposing) +31   Autofac.Util.Disposable.Dispose() +43   Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) in d:\TeamCity\Projects\Orchard-Default\src\Orchard\Mvc\Routes\ShellRoute.cs:151   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +375

Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction

[SqlException (0x80131904): Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction.]   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +404   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +412   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1363   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +6368941   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +6370642   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +538   System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +689   System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +327   NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd) +675   NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation) +21   NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session) +1656
[GenericADOException: could not insert: [part name omited][SQL: INSERT INTO table name omited () VALUES (?, ?, ?, ?, ?, ?, ?, ?)]]   NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session) +2231   NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session) +263   NHibernate.Action.EntityInsertAction.Execute() +293   NHibernate.Engine.ActionQueue.ExecuteActions(IList list) +110   NHibernate.Engine.ActionQueue.ExecuteActions() +20   NHibernate.Event.Default.AbstractFlushingEventListener.PerformExecutions(IEventSource session) +506   NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event) +100   NHibernate.Impl.SessionImpl.Flush() +509   NHibernate.Transaction.DistributedTransactionContext.System.Transactions.IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment) +694
[TransactionAbortedException: The transaction has aborted.]   System.Transactions.TransactionStatePromotedAborted.PromotedTransactionOutcome(InternalTransaction tx) +228077   System.Transactions.CommittableTransaction.Commit() +453   System.Transactions.TransactionScope.InternalDispose() +638   System.Transactions.TransactionScope.Dispose() +2492   Orchard.Data.TransactionManager.System.IDisposable.Dispose() in d:\TeamCity\Projects\Orchard-Default\src\Orchard\Data\TransactionManager.cs:47   Autofac.Core.Disposer.Dispose(Boolean disposing) +82   Autofac.Util.Disposable.Dispose() +43   Autofac.Core.Lifetime.LifetimeScope.Dispose(Boolean disposing) +31   Autofac.Util.Disposable.Dispose() +43   Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) in d:\TeamCity\Projects\Orchard-Default\src\Orchard\Mvc\Routes\ShellRoute.cs:151   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +375

 

I read through this http://orchard.codeplex.com/discussions/241153 but we are just using the IContentManager in our controller constructor which is created per instance.

Coordinator
Aug 18, 2011 at 6:11 PM

Never seen that. You should file a bug for that. Can you reproduce it on different machines ?

Aug 19, 2011 at 8:29 AM

Yes, I can reproduce it on different machines. At present I can reproduce it on a Windows 2003 server, a Windows 2008 R2 server, but not on a Windows 7 machine. I have compared the DTC settings between the Windows 2008 machine and the Windows 7 machine, but I can't see any difference.

Aug 19, 2011 at 9:23 AM

To add to this....

 

On the Windows 7 machines our Orchard site runs fine without DTC enabled. However, on the Windows Server 2003 or 2008 the site errors if DTC is not enabled. I would rather not use DTC anyway. Any ideas why this would be the case or how I can stop the sites on 2003/2008 using DTC?