views:

35

answers:

1

I'm currently working on creating a custom connection provider for HNibernate very similar to the one mentioned here. In it, they specify a separate connection string within the hibernate.cfg.xml parameters. However, when I go to add this new parameter, like so...

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory>
        <property name="connection.provider">MyNameSpace.FailoverConnectionProvider</property>
        <property name="dialect">NHibernate.Dialect.MsSql2008Dialect,NHibernate</property>
        <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
        <property name="connection.connection_string">[primary connection string]</property>
        <property name="connection.failover_connection_string">[failover connection string]</property>
        <property name="proxyfactory.factory_class">NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
        ...
    </session-factory>
</hibernate-configuration>

... I am treated to this exception message:

InnerException  {"The 'name' attribute is invalid - The value 'connection.failover_connection_string' is invalid according to its datatype 'String' - The Enumeration constraint failed."}  System.Exception {System.Xml.Schema.XmlSchemaValidationException}

My question is: is it even possible to add custom properties to the NHibernate configuration file? If so, how?

Thanks!

+1  A: 

It's not possible to add properties to the NHibernate configuration file because it's schema-validated (and you can't change the schema).

Anyway, that's not the place to put anything other than the NHibernate core configuration itself.

Everything else should be in its own location, be it a custom section in the app.config file, a key in the appSettings section, etc.

Diego Mijelshon