Once again: Could not find the dialect in the configuration

487 views
Skip to first unread message

Jan Apel

unread,
Feb 10, 2010, 11:18:22 AM2/10/10
to nhusers
Hello Folks,
I'm becoming desperate trying to get NHibernate to work.
I'm trying to use the latest version in a MS SQL 2005 Environment.
My hibernate.cfg.xml file looks like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="hibernate-configuration"
type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" />
</configSections>

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</
property>
<property name="connection.connection_string">
Server=sqlserver;Initial Catalog=mydb;User
Id=username;Password=password
</property>
<property name="proxyfactory.factory_class">
NHibernate.ByteCode.LinFu.ProxyFactoryFactory,
NHibernate.ByteCode.LinFu
</property>
</session-factory>
</hibernate-configuration>
</configuration>

And my execution file looks like this:

public ExecutionService()
{
Configuration cfg = new Configuration();
cfg.AddFile("hibernate.cfg.xml");
ISessionFactory factory = cfg.BuildSessionFactory();
session = factory.OpenSession();
}


Besides that, i set the config of hibernate.cfg.xml to always copy to
the bin directory

But I keep getting the following exception:

NHibernate.MappingException: Could not compile the mapping document:
hibernate.cfg.xml ---> System.InvalidOperationException: Could not
find the dialect in the configuration


Any ideas? I've tried every existing sort of configuration without
success :-(

Best regards,

Jan

sbohlen

unread,
Feb 10, 2010, 11:26:27 AM2/10/10
to nhusers
You're conflating ideas for what hibernate.cfg.xml should look like in
the context of an app.config / web.config situation and what it should
look like when its a stand-alone file.

Use *just* this for your hibernate.cfg.xml (no configSections stuff
needed):

<?xml version="1.0" encoding="utf-8" ?>


<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">NHibernate.Dialect.MsSql2005Dialect</
property>
<property name="connection.connection_string">
Server=sqlserver;Initial Catalog=mydb;User
Id=username;Password=password
</property>
<property name="proxyfactory.factory_class">
NHibernate.ByteCode.LinFu.ProxyFactoryFactory,
NHibernate.ByteCode.LinFu
</property>
</session-factory>
</hibernate-configuration>

Robert Rudduck

unread,
Feb 10, 2010, 11:26:36 AM2/10/10
to nhu...@googlegroups.com
The declaration for dialect should be...

<add key="hibernate.dialect" value="" />

This link may help you out:

https://www.hibernate.org/362.html


--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.


Robert Rudduck

unread,
Feb 10, 2010, 11:42:24 AM2/10/10
to nhu...@googlegroups.com
You are right, it appears you can do it that way now. I haven't used the xml configuration for NH for a while now....

http://dotnetslackers.com/articles/aspnet/Configuring-NHibernate-with-ASP-NET.aspx

On Wed, Feb 10, 2010 at 10:38 AM, Jan Apel <jan....@gmail.com> wrote:
Hello Robert,

I thought that was in older versions. Somewhere I read the new
convention was just "dialect" and without using keys.

Jan


On 10 Feb., 17:26, Robert Rudduck <rob...@rpowered.net> wrote:
> The declaration for dialect should be...
>
> <add key="hibernate.dialect" value="" />
>
> This link may help you out:
>
> https://www.hibernate.org/362.html
>

Jan Apel

unread,
Feb 10, 2010, 11:42:10 AM2/10/10
to nhusers
Hm, never used google groups before, so I'm sorry for replying to you
both.

Tried using sbohlens code, but I still get the same exception.

@Robert Rudduck
I thought that was the old convention.
I read somewhere that since 2.0 there is no "hibernate.dialect" but
just "dialect" and there are no keys but properties.

Any other ideas?

Jan

On 10 Feb., 17:26, Robert Rudduck <rob...@rpowered.net> wrote:

> The declaration for dialect should be...
>
> <add key="hibernate.dialect" value="" />
>
> This link may help you out:
>
> https://www.hibernate.org/362.html
>

> > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com>

John Davidson

unread,
Feb 10, 2010, 12:33:34 PM2/10/10
to nhu...@googlegroups.com
I think you are missing the "connection.provider" property which is also required in the <session-factory> section

John Davidson

To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.

Robert Rudduck

unread,
Feb 10, 2010, 12:34:17 PM2/10/10
to nhu...@googlegroups.com
Not a problem. It appears you are right (sorry about that, I only use FluentNhibernate now so I am a bit rusty).

The only omission I see from what I remember being required is that you arent specifying the connection.provider or connection.driver_class. Not sure if those are required or not, but it can't hurt to try.

http://www.svendtofte.com/serverside/setting-up-nhibernate-20/
http://www.davesquared.net/2008/08/configuration-changes-in-nhibernate-20.html

To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.

Jan Apel

unread,
Feb 11, 2010, 4:47:07 AM2/11/10
to nhusers
Now I added the connection provider property, but I'm still getting
the same exception :-(

my hibernate.cfg.xml looks now like this:

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="dialect">
NHibernate.Dialect.MsSql2005Dialect
</property>

<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="connection.connection_string">
Server=server;Initial Catalog=db;User


Id=username;Password=password
</property>
<property name="proxyfactory.factory_class">
NHibernate.ByteCode.LinFu.ProxyFactoryFactory,
NHibernate.ByteCode.LinFu
</property>
</session-factory>
</hibernate-configuration>

and my class:

...


public ExecutionService()
{
Configuration cfg = new Configuration();
cfg.AddFile("hibernate.cfg.xml");
ISessionFactory factory = cfg.BuildSessionFactory();
session = factory.OpenSession();

}
...

Unbehandelte Ausnahme: NHibernate.MappingException: Could not compile


the mapping document: hibernate.cfg.xml --->
System.InvalidOperationException: Could not find the dialect in the
configuration

bei NHibernate.Dialect.Dialect.GetDialect(IDictionary`2 props)
bei
NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument
doc)
--- Ende der internen Ausnahmestapelüberwachung ---
bei NHibernate.Cfg.Configuration.LogAndThrow(Exception exception)
bei
NHibernate.Cfg.Configuration.AddValidatedDocument(NamedXmlDocument
doc)
bei NHibernate.Cfg.Configuration.ProcessMappingsQueue()
bei
NHibernate.Cfg.Configuration.AddDocumentThroughQueue(NamedXmlDocument
document)
bei NHibernate.Cfg.Configuration.AddXmlReader(XmlReader hbmReader,
String name)
bei NHibernate.Cfg.Configuration.AddXmlFile(String xmlFile)
bei NHibernate.Cfg.Configuration.AddFile(String xmlFile)
bei....ExecutionService..ctor() in ...ExecutionService.cs:Zeile 20.
bei ....Program.Main(String[] args) in ...Program.cs:Zeile 12.


Any other ideas?

Jan Apel

unread,
Feb 11, 2010, 5:24:07 AM2/11/10
to nhusers
@bs.stack

my config file is being copied to the bin/Release folder.
I also just tried deleting it and when I do so, I get a "file not
found" error, so I think it is being copied and found.

I could start crying now :(

John Davidson

unread,
Feb 11, 2010, 6:53:16 AM2/11/10
to nhu...@googlegroups.com
Then you also need the connection.driver_class property - but I dont know what the correct setting is for Sql2005.

John Davidson

Fabio Maulo

unread,
Feb 11, 2010, 7:22:05 AM2/11/10
to nhu...@googlegroups.com
Don't cry... do it step by step and you will find the reason.
The problem is not what you are writing in the configuration file but in your code.

var nh_conf = new Configuration();
nh_conf.Configure();


2010/2/11 Jan Apel <jan....@gmail.com>
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.




--
Fabio Maulo

Fabio Maulo

unread,
Feb 11, 2010, 7:24:59 AM2/11/10
to nhu...@googlegroups.com
          Configuration cfg = new Configuration();
           cfg.AddFile("hibernate.cfg.xml");
           ISessionFactory factory = cfg.BuildSessionFactory();
           session = factory.OpenSession();

In that code you are adding the session-factory configuration as a mapping file.
Please review this wiki
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.




--
Fabio Maulo

Jan Apel

unread,
Feb 12, 2010, 6:08:50 AM2/12/10
to nhusers
Thank you all for your help!
I always thought cfg.AddFile was to specify the configfile... Well,
thanks for the info!
I'm now getting closer.

Jan

On 11 Feb., 13:24, Fabio Maulo <fabioma...@gmail.com> wrote:
>           Configuration cfg = new Configuration();
>            cfg.AddFile("hibernate.cfg.xml");
>            ISessionFactory factory = cfg.BuildSessionFactory();
>            session = factory.OpenSession();
>
> In that code you are adding the session-factory configuration as a mapping
> file.

> Please review this wikihttp://nhforge.org/wikis/howtonh/your-first-nhibernate-based-applicat...
>
> 2010/2/10 Jan Apel <jan.a...@gmail.com>

> > nhusers+u...@googlegroups.com<nhusers%2Bunsu...@googlegroups.com>

Reply all
Reply to author
Forward
0 new messages