Hi, ... one ... big question in regards to configuration files. In our application, database settings is currently loaded from
web.config:
In
web.config:
<?xml version="1.0" encoding="utf-8" ?>
Code:
<configuration>
<configSections>
<sectionGroup name="settings">
<section name="dbsettings" type="application.utilities.settings.DBSettingsHandler, Utility" />
... other stuff ...
</sectionGroup>
... other stuff ..
</configSections>
[b]*** Custom configuration section (Database settings):[/b]
<dbsettings db_ip="localhost" db_port="1433" db_user="ATHKAPPUSER" domain="ATFE" db_password="interim" db_initcat="Security" db_provider="MICROSOFTSQL" />
... the rest of it ...
</configuration>
During application start up, database setting is loaded from custom config section as follows:
Code:
dbConfig = CType(_webctx.GetConfig("settings/dbsettings"), DBSettings)
conn_str = dbConfig.ConnectionString
oConn = ConnFactory.CreateConn(conn_str)
... the rest of it ...
With NHibernate, database settings is loaded from its own configuration file - for example,
ABC.cfg.xml, instead of
web.config:
Code:
Dim DbCfgAs New Configuration
Dim factory As ISessionFactory
Dim o_session As ISession
Dim dbCfgFilePath As String
dbCfgFilePath = Request.ServerVariables("APPL_PHYSICAL_PATH") + "bin\ABC.cfg.xml"
DbCfg.Configure(dbCfgFilePath )
DbCfg.AddAssembly("MyAssemblyName")
factory = DbCfg.BuildSessionFactory()
o_session = factory.OpenSession()
Is it possible for me to set NHibernate database configurations using custom configuration sections in
web.config instead of using
ABC.cfg.xml? Perhaps to do this programmatically so I don't need to have
MULTI-CONFIGURATION files?
Thanks in advance.