Skip to content

SessionFactory “Database was not configured through Database method” #1

@simonstrohecker

Description

@simonstrohecker

Hello,

I am trying to deploy an API application on IIS 10 with Visual Studio Community 2015 and when I try to publish it I get this error :

"An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.\r\n\r\n * Database was not configured through Database method.\r\n"

This is my hibernate configuration in 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>

Here the 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();                     

}`

I had a look to all the other solution I could find on Internet but found nothing that could solve my problem. Also I cannot see any InnerExceptions...

Do you have a solution to solve this?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions