Windows 服务和 Nhibernate

发布于 2024-09-27 08:42:26 字数 3343 浏览 3 评论 0原文

我有一个 Windows 服务,它有一个计时器,在timer_Elapsed 事件处理程序中,将调用另一个组件的方法,该方法应该查看数据库并获取或更新一些记录。这个过程每 2 分钟发生一次。我使用 nhibernate 来获取数据组件中的访问。当我从单元测试运行该方法时,它工作正常,这意味着配置和映射是正确的,但是从 Windows 服务我得到这个异常:

FluentNHibernate.Cfg.FluentConfigurationException was caught
  Message="An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.\r\n\r\n"
  Source="FluentNHibernate"
  StackTrace:
       at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 121
 InnerException: NHibernate.MappingException
       Message="Could not configure datastore from input stream (XmlDocument)"
       Source="NHibernate"
       StackTrace:
            at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
            at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
            at NHibernate.Cfg.Configuration.AddDocument(XmlDocument doc, String name)
            at NHibernate.Cfg.Configuration.AddDocument(XmlDocument doc)
            at FluentNHibernate.PersistenceModel.Configure(Configuration cfg) in d:\Builds\FluentNH\src\FluentNHibernate\PersistenceModel.cs:line 265
            at FluentNHibernate.Cfg.FluentMappingsContainer.Apply(Configuration cfg) in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentMappingsContainer.cs:line 141
            at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg) in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\MappingConfiguration.cs:line 64
            at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 112
       InnerException: System.TypeInitializationException
            Message="The type initializer for 'NHibernate.Util.TypeNameParser' threw an exception."
            Source="NHibernate"
            TypeName="NHibernate.Util.TypeNameParser"
            StackTrace:
                 at NHibernate.Util.TypeNameParser.Parse(String type, String defaultNamespace, String defaultAssembly)
                 at NHibernate.Cfg.ClassExtractor.ClassEntry..ctor(String extends, String className, String entityName, String assembly, String namespace)
                 at NHibernate.Cfg.ClassExtractor.GetClassEntries(XmlDocument document)
                 at NHibernate.Cfg.MappingsQueue.AddDocument(NamedXmlDocument document)
                 at NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document)
                 at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name)
                 at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
            InnerException: System.Threading.ThreadAbortException
                 Message="Exception of type 'System.Threading.ThreadAbortException' was thrown."
                 InnerException: 

这是timer_elapsed 事件处理程序中的代码:

private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)


   {
        lock (processLock)
        {
            DoWorkComponent component= new DoWorkComponent ();
            component.DoWorkMethod();
        }
    }

有人知道如何解决这个问题吗?我需要有不同的设置吗?

提前致谢,

萨沙

I have a Windows service which has a timer and in the timer_Elapsed event handler a method from another component will be called which is supposed to look into db and get or update some records.This process will happen every 2 minutes.I used nhibernate for data access in the component. When I run the method from unit test it is working fine which means the configurations and mappings are correct, but from windows service I get this exception:

FluentNHibernate.Cfg.FluentConfigurationException was caught
  Message="An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.\r\n\r\n"
  Source="FluentNHibernate"
  StackTrace:
       at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 121
 InnerException: NHibernate.MappingException
       Message="Could not configure datastore from input stream (XmlDocument)"
       Source="NHibernate"
       StackTrace:
            at NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
            at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
            at NHibernate.Cfg.Configuration.AddDocument(XmlDocument doc, String name)
            at NHibernate.Cfg.Configuration.AddDocument(XmlDocument doc)
            at FluentNHibernate.PersistenceModel.Configure(Configuration cfg) in d:\Builds\FluentNH\src\FluentNHibernate\PersistenceModel.cs:line 265
            at FluentNHibernate.Cfg.FluentMappingsContainer.Apply(Configuration cfg) in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentMappingsContainer.cs:line 141
            at FluentNHibernate.Cfg.MappingConfiguration.Apply(Configuration cfg) in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\MappingConfiguration.cs:line 64
            at FluentNHibernate.Cfg.FluentConfiguration.BuildConfiguration() in d:\Builds\FluentNH\src\FluentNHibernate\Cfg\FluentConfiguration.cs:line 112
       InnerException: System.TypeInitializationException
            Message="The type initializer for 'NHibernate.Util.TypeNameParser' threw an exception."
            Source="NHibernate"
            TypeName="NHibernate.Util.TypeNameParser"
            StackTrace:
                 at NHibernate.Util.TypeNameParser.Parse(String type, String defaultNamespace, String defaultAssembly)
                 at NHibernate.Cfg.ClassExtractor.ClassEntry..ctor(String extends, String className, String entityName, String assembly, String namespace)
                 at NHibernate.Cfg.ClassExtractor.GetClassEntries(XmlDocument document)
                 at NHibernate.Cfg.MappingsQueue.AddDocument(NamedXmlDocument document)
                 at NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument document)
                 at NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader, String name)
                 at NHibernate.Cfg.Configuration.AddInputStream(Stream xmlInputStream, String name)
            InnerException: System.Threading.ThreadAbortException
                 Message="Exception of type 'System.Threading.ThreadAbortException' was thrown."
                 InnerException: 

Here is the code in timer_elapsed event handler:

private void timer1_Elapsed(object sender, System.Timers.ElapsedEventArgs e)


   {
        lock (processLock)
        {
            DoWorkComponent component= new DoWorkComponent ();
            component.DoWorkMethod();
        }
    }

Does anybody know how this can be fixed? Do I need to have different settings?

Thanks in Advance,

Sacha

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

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

发布评论

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

评论(1

骄兵必败 2024-10-04 08:42:26

问题解决了。该错误与运行该程序的用户帐户有关
服务:

http://groups.google.ca/group /fluence-nhibernate/browse_thread/thread/bafd5dddea909eb?hl=en

谢谢,
萨沙

Problem solved. The error was related to the user account that runs the
service:

http://groups.google.ca/group/fluent-nhibernate/browse_thread/thread/bafd5dddea909eb?hl=en

Thanks,
Sacha

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文