-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Many Connection String
PostPosted: Tue Jul 12, 2005 9:37 am 
Hi,

My application uses 2 different DB.
So I need to define 2 connection string.

In my web.config file I have already a "hibernate.connection.connection_string" property...

I don't know how to define a second connection string and how to use it.

Thank you for your help.

KR
Julien


Top
  
 
 Post subject:
PostPosted: Wed Jul 13, 2005 2:21 am 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
unfortunately, this feature is not yet available.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 13, 2005 9:17 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
NHibernate's Configuration and SessionFactory work with ONE Database. So if you have many databases then you must have many Cfg and SessFac.
You can put their configurations in two xml files (don't use web.config)

Remember that it is not possible for NHibernate to create any link/mapping between your two databases (it is up to your application)

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 11:44 am 
Newbie

Joined: Fri Jul 29, 2005 11:35 am
Posts: 1
I have kind of the same situation, but I'm thinking about having two projects in my solution - each one has it's own app.config that knows how to get its session factory based on the configuration xml.

In my case I am integrating two systems and have to 'translate' similar objects between the two dbs (accounts look different in each db for example).

In that case I will call a command with one object type, create an instance of the new object and do my translation.

Because I can separate these in separate projects I think I can get by with this.

Anyone done anything like this, or should I create a configuration factory that returns the appropriate type that has parsed a specific xml?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 01, 2005 4:24 am 
Beginner
Beginner

Joined: Thu May 12, 2005 3:41 am
Posts: 24
Location: London, UK
Using app.config or web.config is the easiest way to configure NHibernate, but is not the only way.

The Configuration constructor configures NH from the app.config or web.config file, if it exists. After constructing the object, you can call the Configure() method to overwrite the initial values. This has four overloads, which can configure NH from an XML file in the file system, from a resource in an assembly or from an XmlTextReader. The following code will build two session factories from two different config files.

Code:
SessionFactory factory1 = new Configuration()
      .Configure(configFile1)
      .BuildSessionFactory();

SessionFactory factory2 = new Configuration()
      .Configure(configFile2)
      .BuildSessionFactory();


The following is based on a config file from the NHibernate test suite
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration  xmlns="urn:nhibernate-configuration-2.0" >
  <session-factory name="NHibernate.Test">
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">Server=localhost;initial catalog=nhibernate;User Id=;Password=</property>
    <property name="show_sql">false</property>
    <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
    <property name="use_outer_join">true</property>
    <property name="command_timeout">444</property>
    <property name="query.substitutions">true 1, false 0, yes 1, no 0</property>
    <mapping file="ABC.hbm.xml" />
    <mapping resource="NHibernate.DomainModel.Simple.hbm.xml" assembly="NHibernate.DomainModel" />
  </session-factory>
</hibernate-configuration>


You can also configure NH programatically using the Properties collection of the Configuration object and various methods to add mappings from an assembly, xml file, resource, etc.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.