The Darkside

Shedding light on things and stuff

 
  Home :: Contact :: Syndication  :: Login
  75 Posts :: 0 Stories :: 49 Comments :: 2 Trackbacks

Ads

Archives

Post Categories

Open Source Projects

Other Blogs

This is the third post I'm doing related to a Castle ActiveRecord/NHibernate/lazy loading/sessionscope error that occurs. The first two are here and here.

I received a mail the other day about an ActiveRecord/NHibernate error begin thrown in an application (web application, actually), which subsequently turned out to be another instance of the "failed to lazily initialize a collection, no session or session was closed" error. While browsing through the ActiveRecord source code when trying to solve the previous sessionscope problems I'd had, I came across an HttpModule called "SessionScopeWebModule" in the Castle.ActiveRecord.Framework namespace, and so the lightbulb switched on. I did a quick search for more info on this module at castleproject.org and found this article

You simply add the module in as you'd do for any HttpModule, as follows:

<httpModules>
  <add name="ar.sessionscope" type="Castle.ActiveRecord.Framework.SessionScopeWebModule, Castle.ActiveRecord" />
</httpModules>

 When you initialise the ActiveRecord framework, however, you still get an error related to the fact that you don't have the "isWeb" attribute set to true. That's simply remedied by modifying the configuration section for ActiveRecord as follows:

<activerecord isWeb="true">
  <config>
    <add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
    <add key="dialect" value="NHibernate.Dialect.MsSql2005Dialect" />
    <add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
    <add key="connection.connection_string" value="Server=(local);initial catalog=myDatabase;Integrated Security=SSPI" />
    <add key="show_sql" value="false" />
  </config>
</activerecord>

posted on Friday, October 10, 2008 12:00 AM

Feedback

# re: Castle ActiveRecord - Lazy Loading and session scopes in the web 10/25/2008 8:02 AM free programming ebooks
Nice website, simple but work very well
Good job.

Comments have been closed on this topic.