2011-02-03 69 views
0

現在,我有我的配置文件來指定活動記錄/ NHibernate的連接字符串,像這樣:負載連接字符串編程

<activerecord> 
    <config type="Navtrak.Business.Schemas.CommonSchemas.Models.NavtrakOperations.NavtrakOperationsDatabase`1, CommonSchemas"> 
     <add key="connection.connection_string" value="connstring1" /> 
     <add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver" /> 
     <add key="dialect" value="NHibernate.Dialect.MsSql2005Dialect" /> 
     <add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider" /> 
     <add key="show_sql" value="true" /> 
     <add key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle" /> 
    </config> 
    <config type="Navtrak.Business.Schemas.CommonSchemas.Models.Users.UsersDatabase`1, CommonSchemas"> 
     <add key="connection.connection_string" value="connstring2" /> 
     <add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver" /> 
     <add key="dialect" value="NHibernate.Dialect.MsSql2005Dialect" /> 
     <add key="connection.provider" value="NHibernate.Connection.DriverConnectionProvider" /> 
     <add key="show_sql" value="true" /> 
     <add key="proxyfactory.factory_class" value="NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle" /> 
    </config> 
    </activerecord> 

然後我初始化活動記錄:

if (!ActiveRecordStarter.IsInitialized) 
       ActiveRecordStarter.Initialize(typeof(SimpleModel).Assembly, ActiveRecordSectionHandler.Instance); 

這些連接字符串必須是數據庫驅動的,所以我需要一種以編程方式設置它們的方法。我該怎麼做?請記住,我連接到多個數據庫,以防萬一...

回答