Castle ActiveRecord 错误“会话已关闭”
我正在尝试开始使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 SessionScope。
在Request___Start中,创建一个新的SessionScope()并将其释放到Request_End中。
Use a SessionScope.
In Request___Start, create a new SessionScope() and dispose it in Request_End.
在您的 ApplicationStart 中执行以下操作:
In Your ApplicationStart do something like: