Home

Castle Stronghold

.Net 2 connection strings

The .Net 2.0 allows specific connection string sections on the configuration file. Those can be managed by UI tools that comes with the framework. You can use them to supply ActiveRecord with a connection string:


<configSections>
    <section name="activerecord"
             type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord" />
    <section name="activerecord-asp-net-2.0"
             type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord" />
</configSections>

<connectionStrings>
    <add name="Test" connectionString="Test Connection String"/>
</connectionStrings>

<activerecord-asp-net-2.0>
    <config>
        <add key="hibernate.connection.connection_string" value="ConnectionString = ${Test}" />
    </config>
</activerecord-asp-net-2.0>

NHibernate v1.2+ introduced support for .Net 2.0 connectionStrings section via the hibernate.connection.connection_string_name property. So the previous declaration can be more simplified to the following:


<activerecord-asp-net-2.0>
    <config>
        <add key="hibernate.connection.connection_string_name" value="Test" />
    </config>
</activerecord-asp-net-2.0>

Google
Search WWW Search castleproject.org