Castle ActiveRecord 错误“会话已关闭”

发布于 2024-08-03 03:26:45 字数 1329 浏览 2 评论 0原文

我正在尝试开始使用 Castle ActiveRecord,但我一直试图让它在 ASP.NET(MVC,如果重要的话)应用程序中工作。
事实上,我在查询期间收到了 ObjectDisposeException,并显示以下消息:

会议已结束!
对象名称:“ISession”。

我正在从 XML 文件(如入门中所示)初始化 ActiveRecord,其内容为:


<?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>

不幸的是,主要是由于缺乏文档以及我对温莎城堡的完全无知,我无法找出应该如何配置它让它发挥作用,所以如果你们中有人能告诉我缺少什么或出了什么问题,我将不胜感激。

预先感谢

编辑:我可能应该指定此错误发生在我在 Application_Start 中生成的线程上,该线程负责运行某些维护任务。

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:

Session is closed!
Object name: 'ISession'.

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.

Thanks in advance

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

御守 2024-08-10 03:26:45

使用 SessionScope。

在Request___Start中,创建一个新的SessionScope()并将其释放到Request_End中。

Use a SessionScope.

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

待天淡蓝洁白时 2024-08-10 03:26:45

在您的 ApplicationStart 中执行以下操作:

void Application_Start(...)  {
    using( SessionScope session = new SessionScope() ) {
        // Your Startup Logic here
        session.Flush();
    }
}

In Your ApplicationStart do something like:

void Application_Start(...)  {
    using( SessionScope session = new SessionScope() ) {
        // Your Startup Logic here
        session.Flush();
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文