SessionFactory“未通过数据库方法配置数据库”

时间:2018-10-12 08:40:43

标签: c# .net sql-server visual-studio iis-10

我正在尝试使用Visual Studio Community 2015在IIS 10上部署API应用程序,当我尝试发布它时,出现此错误:

“在创建SessionFactory时使用了无效或不完整的配置。请检查PotentialReasons集合和InnerException以获取更多详细信息。\ r \ n \ r \ n *未通过数据库方法配置数据库。\ r \ n”

我从here下载了源代码。

这是我在Web.config中的休眠配置:

 <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>      
      <property name="connection.connection_string">Data Source=DEV01\SQLEXPRESS;Initial Catalog=ACCEPT_DB;Integrated Security=True</property>
      <property name="adonet.batch_size">10</property>
      <property name="show_sql">true</property>
      <property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>      
      <property name="command_timeout">60</property>
      <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>     
    </session-factory>
  </hibernate-configuration>

这是NHibernateSessionFactory:

private NhibernateSessionFactory()
{
    var baseConfig = new Configuration();
    baseConfig.Configure();

    //having one mapping class path is enough.
    var config = Fluently.Configure(baseConfig).Mappings(m => m.FluentMappings.AddFromAssemblyOf<UserMap>()).Mappings(m => m.FluentMappings.AddFromAssemblyOf<RoleMap>()).ExposeConfiguration(cfg => cfg.Properties.Add("use_outer_join", "true"));

    try
    {
        if (System.Configuration.ConfigurationManager.AppSettings["DbSchemaDrop"].CompareTo("1") == 0)
            config.ExposeConfiguration(cfg => new SchemaExport(cfg).Drop(false, true));
        if (System.Configuration.ConfigurationManager.AppSettings["DbSchemaCreate"].CompareTo("1") == 0)
            config.ExposeConfiguration(cfg => new SchemaExport(cfg).Create(false, true));
        if (System.Configuration.ConfigurationManager.AppSettings["DbSchemaUpdate"].CompareTo("1") == 0)
            config.ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true));
    }
    catch (Exception e)
    {
        throw (e);
    }

    SessionFactory = config.BuildSessionFactory();                     
}

我看了一下在Internet上可以找到的所有其他解决方案,但是没有找到可以解决我的问题的解决方案。我也看不到任何InnerExceptions ...

有人有解决方案吗?

谢谢!

0 个答案:

没有答案