Help! '{"The connection object can not be enlisted in transaction scope."}'

Topics: Troubleshooting, Writing modules
Jun 21, 2011 at 7:51 PM

Hi there,

I am porting an existing site to run on Orchard, therefore I am maintaining the existing infrastructure for the non-cms parts (EF, SQL Server).

In my module that deals with the core functionallity I am accessing a sql server database using Entity Framework 4 as the ORM (Orchard is running sql ce).
In my controller I can communicate with just fine with sql server via entity framework.
However as soon as the controller exists and Orchard CMS takes over I get the following exception (If I make no calls to the database, all works just fine.).

The code running on the controller is pretty basic:

            using (var rep = RepositoryManager.GetRepository<AcoboCollection>())
            {
                var test = (from p in rep.Fetch() where p.ParentCollection == null select p).ToList();
            }

            return View();
 

 

The connection object can not be enlisted in transaction scope.

 

[ADOException: While preparing SELECT contentite0_.Id as Id49_0_, contentite0_.Data as Data49_0_, contentite0_.ContentType_id as ContentT3_49_0_ FROM Orchard_Framework_ContentItemRecord contentite0_ WHERE contentite0_.Id=@p0 an error occurred]
   NHibernate.AdoNet.AbstractBatcher.Prepare(IDbCommand cmd) +305
   NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) +100
   NHibernate.Loader.Loader.GetResultSet(IDbCommand st, Boolean autoDiscoverTypes, Boolean callable, RowSelection selection, ISessionImplementor session) +365
   NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +420
   NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Boolean returnProxies) +106
   NHibernate.Loader.Loader.LoadEntity(ISessionImplementor session, Object id, IType identifierType, Object optionalObject, String optionalEntityName, Object optionalIdentifier, IEntityPersister persister) +406
   NHibernate.Loader.Entity.AbstractEntityLoader.Load(ISessionImplementor session, Object id, Object optionalObject, Object optionalId) +69
   NHibernate.Loader.Entity.AbstractEntityLoader.Load(Object id, Object optionalObject, ISessionImplementor session) +48
   NHibernate.Persister.Entity.AbstractEntityPersister.Load(Object id, Object optionalObject, LockMode lockMode, ISessionImplementor session) +177
   NHibernate.Event.Default.DefaultLoadEventListener.LoadFromDatasource(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) +218
   NHibernate.Event.Default.DefaultLoadEventListener.DoLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) +818
   NHibernate.Event.Default.DefaultLoadEventListener.Load(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) +372
   NHibernate.Event.Default.DefaultLoadEventListener.ProxyOrLoad(LoadEvent event, IEntityPersister persister, EntityKey keyToLoad, LoadType options) +390
   NHibernate.Event.Default.DefaultLoadEventListener.OnLoad(LoadEvent event, LoadType loadType) +1188
   NHibernate.Impl.SessionImpl.FireLoad(LoadEvent event, LoadType loadType) +208
   NHibernate.Impl.SessionImpl.Get(String entityName, Object id) +195
   NHibernate.Impl.SessionImpl.Get(Type entityClass, Object id) +158
   NHibernate.Impl.SessionImpl.Get(Object id) +202
   Orchard.Data.Repository`1.Get(Int32 id) in C:\Users\User1\cms\Adriana Cobo\Source\OrchardCMS\src\Orchard\Data\Repository.cs:87
   Orchard.Data.Repository`1.Orchard.Data.IRepository<T>.Get(Int32 id) in C:\Users\User1\cms\Adriana Cobo\Source\OrchardCMS\src\Orchard\Data\Repository.cs:56
   Orchard.ContentManagement.DefaultContentManager.Get(Int32 id, VersionOptions options) in C:\Users\User1\cms\Adriana Cobo\Source\OrchardCMS\src\Orchard\ContentManagement\DefaultContentManager.cs:120
   Orchard.ContentManagement.DefaultContentManager.Get(Int32 id) in C:\Users\User1\cms\Adriana Cobo\Source\OrchardCMS\src\Orchard\ContentManagement\DefaultContentManager.cs:101
   Orchard.ContentManagement.ContentGetExtensions.Get(IContentManager manager, Int32 id) in C:\Users\User1\cms\Adriana Cobo\Source\OrchardCMS\src\Orchard\ContentManagement\ContentExtensions.cs:146
   Orchard.Core.Settings.Services.SiteService.GetSiteSettings() in C:\Users\User1\cms\Adriana Cobo\Source\OrchardCMS\src\Orchard.Web\Core\Settings\Services\SiteService.cs:45
   Orchard.Settings.CurrentSiteWorkContext.Get(String name) in C:\Users\User1\cms\Adriana Cobo\Source\OrchardCMS\src\Orchard\Settings\CurrentSiteWorkContext.cs:13
   Orchard.Environment.<>c__DisplayClass7`1.<FindResolverForState>b__2(IWorkContextStateProvider wcsp) in C:\Users\User1\cms\Adriana Cobo\Source\OrchardCMS\src\Orchard\Environment\WorkContextImplementation.cs:32
   System.Linq.WhereSelectArrayIterator`2.MoveNext() +85
   System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source, Func`2 predicate) +166
   Orchard.Environment.WorkContextImplementation.FindResolverForState(String name) in C:\Users\User1\cms\Adriana Cobo\Source\OrchardCMS\src\Orchard\Environment\WorkContextImplementation.cs:32
   System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +72
   Orchard.Environment.WorkContextImplementation.GetState(String name) in C:\Users\User1\cms\Adriana Cobo\Source\OrchardCMS\src\Orchard\Environment\WorkContextImplementation.cs:27
   Orchard.WorkContext.get_CurrentSite() in C:\Users\User1\cms\Adriana Cobo\Source\OrchardCMS\src\Orchard\WorkContext.cs:25
   Orchard.Widgets.Filters.WidgetFilter.OnResultExecuting(ResultExecutingContext filterContext) +2187
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +76
   System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +61
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +391
   System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +61
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +391
   System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +61
   System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +285
   System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +830
   System.Web.Mvc.Controller.ExecuteCore() +136
   System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +232
   System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +39
   System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +68
   System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +44
   System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +42
   System.Web.Mvc.Async.WrappedAsyncResult`1.End() +141
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +54
   System.Web.Mvc.Async.AsyncResultWrapper.End(IAsyncResult asyncResult, Object tag) +40
   System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +61
   System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +31
   System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +56
   System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +110
   System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +38
   Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) in C:\Users\User1\cms\Adriana Cobo\Source\OrchardCMS\src\Orchard\Mvc\Routes\ShellRoute.cs:148
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8920029
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184

 

Jun 21, 2011 at 8:03 PM
Edited Jun 21, 2011 at 8:04 PM

nevermind. Just saw the previous post and was able to solve it by enclosing my data access inside:

using (new TransactionScope(TransactionScopeOption.Suppress)
{
    // db access here
}