Note that there are some explanatory texts on larger screens.

plurals
  1. POConnecting to multiple databases in Active Record
    text
    copied!<p>I'm trying to connect to multiple databases in castle active record (which uses nhibernate.) My config file looks like this:</p> <pre><code>&lt;configSections&gt; &lt;section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord" /&gt; &lt;section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /&gt; &lt;/configSections&gt; &lt;activerecord&gt; &lt;config type="Navtrak.Business.Schemas.CommonSchemas.Models.NavtrakOperations.NavtrakOperationsDatabase`1, CommonSchemas"&gt; &lt;add key="hibernate.connection.connection_string" value="myconnstring" /&gt; &lt;add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" /&gt; &lt;add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect" /&gt; &lt;add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" /&gt; &lt;/config&gt; &lt;config type="Navtrak.Business.Schemas.CommonSchemas.Models.Errors.ErrorsDatabase`1, CommonSchemas"&gt; &lt;add key="hibernate.connection.connection_string" value="Data Source=myconnstring" /&gt; &lt;add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" /&gt; &lt;add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect" /&gt; &lt;add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" /&gt; &lt;/config&gt; &lt;/activerecord&gt; </code></pre> <p>And then I have a base abstract class for each database like this:</p> <pre><code>public abstract class NavtrakOperationsDatabase&lt;T&gt; : ActiveRecordBase&lt;T&gt; { } </code></pre> <p>And then each class inherits from this. I'm then initializing active record like this:</p> <pre><code>ActiveRecordStarter.Initialize(typeof(SimpleModel).Assembly, ActiveRecordSectionHandler.Instance); </code></pre> <p>Which gives me the error:</p> <p><strong>Could not find the dialect in the configuration</strong></p> <p>If I change the activation code to this:</p> <pre><code>ActiveRecordStarter.Initialize( ActiveRecordSectionHandler.Instance, typeof(NavtrakOperationsDatabase&lt;&gt;), typeof(ErrorsDatabase&lt;&gt;) ); </code></pre> <p>Then I get the following error:</p> <p><strong>You have accessed an ActiveRecord class that wasn't properly initialized. There are two possible explanations: that the call to ActiveRecordStarter.Initialize() didn't include Navtrak.Business.Schemas.CommonSchemas.Models.NavtrakOperations.Application class, or that Navtrak.Business.Schemas.CommonSchemas.Models.NavtrakOperations.Application class is not decorated with the [ActiveRecord] attribute.</strong></p> <p>I obviously don't want to include every single class in the Initialize function.</p> <p>Any ideas?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload