'Session is closed!' error

Topics: Customizing Orchard, Troubleshooting, Writing modules
Jul 5, 2012 at 10:28 AM
Edited Jul 5, 2012 at 10:34 AM

I did some updates to our migration command line commands today, and I ran into a 'Session is closed!' exception where before I had no issues.

I have a loop that imports data 100 entries/time.

Before the loop I connect to the mysql backend (old data is on there) and demand a transaction.

 

First time in the loop @ start I create a 'RequiresNew' transaction scope, other times @ start I flush the content, clear it and complete+dispose the transaction scope, before creating a new one.

Sometimes I can 2, sometimes 4+ before I get said message.

Any ideas / hints where to start looking? :/

 

edit: Disabling Q42.DbTranslations resolved my problem - guess that is ok for now (since we'll only use these commands one time when migrating our data) but weird nonetheless :/

Apr 5, 2013 at 11:27 AM
Edited Apr 5, 2013 at 11:35 AM
I think the problem is that the LocalizationService in the translations module is doing data access using an NHibernate session by calling ISessionLocator.For(type). Presumably something is accessing translations code when you're running your migration command. The using statement around the session would dispose it when it exits - when ISessionLocator is used in internal Orchard code it's not disposed this way.

I was doing my own data access in a background task and getting the same error in other background tasks that ran afterwards. Removing the using statement from my code stopped the error for me.