本文介绍了Castle ActiveRecord错误“会话关闭”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想开始使用Castle ActiveRecord,但是我坚持试图使它在ASP.NET(MVC,如果有用)应用程序中工作。

事实上,我在查询期间获取ObjectDisposedException,并显示以下消息:

I'm trying to get started with Castle ActiveRecord but I'm stuck trying to make it work in an ASP.NET (MVC, if it matters) application.
In fact I'm getting an ObjectDisposedException during a query with the following message:

我从一个XML文件(如开始所示)初始化ActiveRecord,其内容是:

I'm initializing ActiveRecord from an XML file (as shown in the getting started) of which the contents are:


<?xml version="1.0" encoding="utf-8" ?>

<activerecord isWeb="true" isDebug="true" threadinfotype="Castle.ActiveRecord.Framework.Scopes.HybridWebThreadScopeInfo, Castle.ActiveRecord">

  <config>
    <add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
    <add key="dialect" value="NHibernate.Dialect.MsSql2008Dialect" />
    <add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />
    <add key="connection.connection_string" value="Data Source=.\SQLEXPRESS;Initial Catalog=testDB;Integrated Security=SSPI" />
    <add key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle" />
    <add key="show_sql" value="true" />
    <add key="default_schema" value="testDB.dbo" />
  </config>

</activerecord>

不幸的是主要是由于缺乏文档和我对城堡温莎的完全无知我找不到应该如何配置它使它工作,所以我会感谢,如果你能告诉我什么缺失或什么问题。

Unfortunately mostly due to lack of documentation and my complete ignorance regarding Castle Windsor I'm not able to find out how should I configure it to make it work, so I'd be thankful if any of you could tell me what's missing or what's wrong.

提前感谢

编辑:我应该指定这个错误发生在我在Application_Start中产生并且负责运行某些维护任务的线程。 / p>

Edit: I should probably specify that this error occurs on a thread which I spawn in Application_Start and which is in charge of running certain maintenance tasks.

推荐答案

使用SessionScope。

Use a SessionScope.

在Request___Start中,创建一个新的SessionScope ()并将其处理在Request_End中。

In Request___Start, create a new SessionScope() and dispose it in Request_End.

这篇关于Castle ActiveRecord错误“会话关闭”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 21:46
查看更多