I’m currently using NHibernate on an ASP.NET project, and wanted to use web config transformations to swap the databases that I am using. To do this, I setup the nhibernate configuration sections in the web config as per usual, that is, similar to this:
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory name="PmqccSessionFa ctory">
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">
Data Source=SQL_SERVER;Initial Catalog=TEST_DATABASE;Integrated Security=SSPI;
</property>
..... etc
<hibernate-configuration>
<session-factory name="PmqccSessionFactory" >
<property xdt:Transform="Replace" xdt:Locator="Match(name)" name="connection.connection_string">
Data Source=SQL_SERVER;Initial Catalog=REAL_DATABASE;Integrated Security=SSPI;
</property>
</session-factory>
</hibernate-configuration>
To solve the issue, I tried to remove the namespace attribute, which appeared to work when I deployed it, but then I ran into some issues with cassini not using the hibernate configuration from the web.config and instead looking for nhibernates own config xml file.
In the end, the solution was to go to my web.release.config file and add the following to the <configuration> tag:
xmlns:hib="urn:nhibernate-configuration-2.2"
<hib:hibernate-configuration>
<hib:session-factory name="PmqccSessionFactory">
<hib:property xdt:Transform="Replace" xdt:Locator="Match(name)" name="connection.connection_string">
Data Source=SQL_SERVER;Initial Catalog=REAL_DATABASE;Integrated Security=SSPI;
</hib:property>
</hib:session-factory>
</hib:hibernate-configuration>
2 comments:
Was the resulting web.config correct? I tried similar setup to yours but the resulting web.config had namespace attribute on the property. element. <property name="default_schema" xmlns:hib="urn:nhibernate-configuration-2.2">xxx</property>
I believe this is the desired result isn't it? We just remove the xmlns from the original to the release and then I believe the web config transformation combines the two.
Did your NHibernate connect successfully after doing this?
Post a Comment