Hi,
I am very new to Spring and NHibernate and have been tasked to investigate how to implement connection string management in a shared hosted environment. We have a ASP.NET 2.0 application that has a "system" database that stores user authentication/authorization data along with their system database connection strings. I am able to get and store this data in the current session using straight SQL against the "system" database. The application itself is written to utilize NHibernate so the "user_data" databases have the same schema for each client. The current web.config and Spring.DAO.config files have are setup as follows.
web.config
Code:
<configSections>
<section name="databaseSettings" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowLocation="false"/>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.WebContextHandler, Spring.Web"/>
<section name="parsers" type="Spring.Context.Support.ConfigParsersSectionHandler, Spring.Core"/>
<section name="typeAliases" type="Spring.Context.Support.TypeAliasesSectionHandler, Spring.Core"/>
</sectionGroup>
<databaseSettings>
<add key="db.datasource" value="server"/>
<add key="db.user" value="user"/>
<add key="db.password" value="pass"/>
<add key="db.database" value="database"/>
</databaseSettings>
<spring>
<context>
<resource uri="assembly://MyAssembly.Data.Config/Spring.DAO.xml"/>
<resource uri="assembly://MyAssembly.Service.Config/Spring.Service.xml"/>
<resource uri="assembly://MyAssembly.Presenter.Config/Spring.Presenter.xml"/>
<resource uri="~/Config/Spring.Web.xml"/>
</context>
<parsers>
<parser type="Spring.Data.DatabaseConfigParser, Spring.Data"/>
<parser type="Spring.Transaction.Config.TxNamespaceParser"/>
</parsers>
<typeAliases>
<alias name="ListPresenter" type="MyAssembly.NET.Presenter.ListPresenter<>, MyAssembly.NET"/>
<alias name="FormPresenter" type="MyAssembly.NET.Presenter.FormPresenter<>, MyAssembly.NET"/>
</typeAliases>
</spring>
Spring.DAO.xml
Code:
.
.
.
<!-- This requires the containing .config file to have a datbaseSettings section -->
<object type="Spring.Objects.Factory.Config.PropertyPlaceholderConfigurer, Spring.Core">
<property name="ConfigSections" value="databaseSettings"/>
</object>
<db:dbProvider id="DbProvider" provider="SqlServer-2.0"
connectionString="Data Source=${db.datasource};Database=${db.database};User ID=${db.user};Password=${db.password};"/>
<object id="SessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryObject, Spring.Data.NHibernate12">
<property name="DbProvider" ref="DbProvider"/>
<property name="MappingAssemblies">
<list>
<value>Intuit.IRES.Data</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="expiration" value="120"/>
<entry key="hibernate.adonet.batch_size" value="10"/>
<entry key="hibernate.cache.provider_class" value="NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache"/>
<entry key="hibernate.cache.use_query_cache" value="true"/>
<entry key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
<entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="hibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect"/>
<entry key="hibernate.current_session_context_class" value="Spring.Data.NHibernate.SpringSessionContext, Spring.Data.NHibernate12"/>
<entry key="hibernate.show_sql" value="false"/>
</dictionary>
</property>
</object>
.
.
.
I have tried to follow the thread of "How to change a connection string at runtime?" on this forum but not sure if I totally understand it in terms of how I could implement it in my project. I have also looked at the MultiDelegatingDbProvider documentation but there seems to be only one para on it in the documentation.
Judging by how these two config files are set up, any tips would be appreciated. In the meantime, I'll keep messing around with the code samples I find to make sense of it all.
Thank you very much in advance.