Cannot build session with NHibernate.Cfg.Configuration

2,901 views
Skip to first unread message

devonlazarus

unread,
Nov 10, 2009, 2:03:46 PM11/10/09
to Fluent NHibernate
I'm almost embarassed to post this, but I just can't seemto track this
one down.

Using hibernate.cfg.xml, my project works fine. Introducing Fluent
NHibernate using API code to configure the session works fine.
However, I can't seem to get Fluent NHibernate to use the
Nhibernate.Cfg.Configuration (which reads hibernate.cfg.xml) to work.

Code that works:

return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2005.Provider
("NHibernate.Connection.DriverConnectionProvider")
.ConnectionString("Data Source=The string works fine...")
.Dialect("NHibernate.Dialect.MsSql2005Dialect")
.Driver("NHibernate.Driver.SqlClientDriver")
.ShowSql()
.AdoNetBatchSize(500)
.ProxyFactoryFactory
("NHibernate.ByteCode.Castle.ProxyFactoryFactory,
NHibernate.ByteCode.Castle"))
.Mappings(m =>
m.FluentMappings.AddFromAssemblyOf<MyType>())
.BuildSessionFactory();

Code that doesn't work:

Configuration cfg = new NHibernate.Cfg.Configuration();

return Fluently.Configure(cfg)
.Mappings(m =>
m.FluentMappings.AddFromAssemblyOf<AccountAttributeType>())
.BuildSessionFactory();

And the associated hibernate.cgf.xml file:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.connection_string">Data Source=The
String works fine...property>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</
property>
<property
name="connection.provider">NHibernate.Connection.DriverConnectionProvider</
property>
<property
name="connection.driver_class">NHibernate.Driver.SqlClientDriver</
property>
<property name="connection.release_mode">auto</property>
<property name="adonet.batch_size">500</property>
<property
name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory,
NHibernate.ByteCode.Castle</property>

<!-- for DEBUG only... -->
<property name="show_sql">true</property>
</session-factory>
</hibernate-configuration>

The unit test error says:

* Database was not configured through Database method

Here is the InnerException stack:

InnerException {"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"} System.Exception
{FluentNHibernate.Cfg.FluentConfigurationException}

InnerException {"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"} System.Exception
{FluentNHibernate.Cfg.FluentConfigurationException}

InnerException {"Could not compile the mapping document:
(XmlDocument)"} System.Exception {NHibernate.MappingException}

InnerException {"Could not find the dialect in the configuration"}
System.Exception {System.InvalidOperationException}

StackTrace " at NHibernate.Dialect.Dialect.GetDialect(IDictionary`2
props)\r\n at NHibernate.Cfg.Configuration.AddValidatedDocument
(NamedXmlDocument doc)"

==================

So I can see it is telling me it can't find the dialect in my
configuration file, however, the config file works fine with plain ol'
NHibernate, and the dialect seems to work when I set the dialect in
code.

I can certianly do the API thing, but I'd really rather use the xml
file. Any ideas on what I'm doing wrong?

Sorry to be such a n00b...

-devon





HMS

unread,
Nov 15, 2009, 8:04:40 PM11/15/09
to Fluent NHibernate
It's telling you that you didn't use the Database call to configure
the database. I don't have the solution on hand atm, but I'll post
back later if you haven't solved it yourself by then ;).

Minhajuddin

unread,
Nov 21, 2009, 11:25:45 AM11/21/09
to Fluent NHibernate
Hi,
Were you able to solve this problem? I am facing the exact same
problem, Would appreciate any help :)

Guido Ziliotti

unread,
Nov 23, 2009, 5:23:16 AM11/23/09
to fluent-n...@googlegroups.com
If your mappings really work with fluent configuration then hibernate.cgf.xml file was not found in the right place. Have you set "Copy always" in "Copy To Output Directory" via hibernate.cgf.xml Properties in Visual Studio for example?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To post to this group, send email to fluent-n...@googlegroups.com
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---


devonlazarus

unread,
Nov 25, 2009, 10:15:39 AM11/25/09
to Fluent NHibernate
@HMS

Unfortunately, I'm not entirely clear on your comment, but I would
very much apprecaite it if you could post back your solution.
> > -devon- Hide quoted text -
>
> - Show quoted text -

devonlazarus

unread,
Nov 25, 2009, 10:19:20 AM11/25/09
to Fluent NHibernate
Hi Guido,

I do have the file set for Copy Always. That was my first thought and
I appreciate the suggestion.

On Nov 23, 2:23 am, Guido Ziliotti <guido.zilio...@gmail.com> wrote:
> If your mappings really work with fluent configuration then
> hibernate.cgf.xml file was not found in the right place. Have you set "Copy
> always" in "Copy To Output Directory" via hibernate.cgf.xml Properties in
> Visual Studio for example?
>
> > name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFa­ctory,
> > fluent-nhibern...@googlegroups.com<fluent-nhibernate%2Bunsubscr­i...@googlegroups.com>
> > For more options, visit this group at
> >http://groups.google.com/group/fluent-nhibernate?hl=en
> > -~----------~----~----~----~------~----~------~--~---- Hide quoted text -
Reply all
Reply to author
Forward
0 new messages