简体   繁体   English

NHibernate引发异常

[英]NHibernate throws exception

I have a WCF service using NHibernate, I am trying to connect this WCF service thru my WPF and get all the records from my SQL db. 我有一个使用NHibernate的WCF服务,我试图通过我的WPF连接此WCF服务,并从我的SQL数据库中获取所有记录。 Some how it throws this exception and i don't have no clue about this.Any please give me a hand to sort this issue. 一些它如何引发此异常,我对此一无所知。任何人都可以帮我解决这个问题。

Exception : 例外情况:

The type initializer for 'Gateway.DataAccess.NHibernateDAO.NHibernateHelper' threw an exception. “ Gateway.DataAccess.NHibernateDAO.NHibernateHelper”的类型初始值设定项引发了异常。

Resulting in: 导致:

An exception occurred while trying to create an instance of type 'Client.Modules.Metadata.ViewModel.StoriesViewModel'. 尝试创建类型为“ Client.Modules.Metadata.ViewModel.StoriesViewModel”的实例时发生异常。

This my NHibernateHelper class 这是我的NHibernateHelper类

namespace Webster.Gateway.DataAccess.NHibernateDAO
{
    public sealed class NHibernateHelper
    {
        private const string CurrentSessionKey = "nhibernate.current_session";

        // An ISessionFactory is threadsafe, many threads can access it concurrently and request ISessions
        private static readonly ISessionFactory sessionFactory;

        // An ISession is a non-threadsafe object that represents a single unit-of-work with the database
        ////private static ISession currentSession; 

        public static ISessionFactory SessionFactory
        {
            get
            {
                return sessionFactory;
            }
        }

        static NHibernateHelper()
        {
            sessionFactory = new Configuration().Configure().BuildSessionFactory();
        }
    }
}

Found the culprit,its nothing to do with my app,all i have to change the Application Pool setting in IIS and the Identity to my user name.I was hosting this WCF service in IIS. 找到了罪魁祸首,这与我的应用程序无关,所有我都需要将IIS中的“应用程序池”设置和“标识”更改为我的用户名。我正在IIS中托管此WCF服务。

It works fine now thanks a lot guys . 现在工作很好,非常感谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM