2011-10-20 55 views
0

我有這個配置NHibernate的配置多個數據庫

var config = new Configuration().Configure(path); 
       config.AddAssembly(Assembly.GetCallingAssembly()); 
       _factory = config.BuildSessionFactory(); 

和nhibernate.cfg.xml文件

<?xml version="1.0" encoding="utf-8" ?> 

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" > 
    <session-factory name="ServiceCenter.DataAccess"> 
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> 
    <property name="connection.connection_string"> 
     Data Source=.\SQLEXPRESS;Initial Catalog=111;User Id=111;Password=111; 
    </property> 
    <property name="show_sql">false</property> 
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> 
    <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property> 

    </session-factory> 
</hibernate-configuration> 

我想有2個連接字符串。我嘗試在配置文件中添加第二個連接字符串和第二個會話工廠,但它是不正確的。

+1

您的問題究竟是什麼?正如你所說,你需要有會話工廠(每個連接到數據庫)。 – zszep

+0

是的,我想連接到2個數據庫,我嘗試添加第二節與另一個名稱,並使用SetProperty(SessionFactoryName,「correct_factory_name」),但然後發生異常 –

+2

您可以看看這篇由卡爾Seguin http://codebetter.com/karlseguin/2009/03/30/using-nhibernate-with-multiple-databases/ – zszep

回答

0

有一個可用的好材料在這裏here