-->
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.  [ 2 posts ] 
Author Message
 Post subject: Changing Database without changing Web.Config
PostPosted: Fri Dec 30, 2005 9:34 am 
Newbie

Joined: Fri Dec 30, 2005 9:27 am
Posts: 1
Location: Argentina
I ve working in a project in which i must work with Access and SQL Server at the same time. Migrating data from one database to other. I try to find the way to work with both but i realize that if i change the web.config my application resets.
So i find a better way, but i am not sure if it is the best way. Here is the code if its useful for you much better.

public enum tipo
{
access = 1,
sql = 2
}

public ISession getSessionByTipo(tipo ti)
{
Configuration config = new Configuration();
IDictionary dir = new Hashtable() ;
string conn;
string dialect;
string driver;

if (ti == tipo.access)
{
conn = this.mdbConn;
dialect = this.mdbDialect;
driver = this.mdbDriver;
}
else
{
conn = this.sqlConn;
dialect = this.sqlDialect;
driver = this.sqlDriver;
}


foreach (DictionaryEntry de in config.Properties)
{
switch (de.Key.ToString())
{
case "hibernate.connection.connection_string":
dir.Add(de.Key.ToString(), conn);
break;
case "hibernate.connection.driver_class":
dir.Add(de.Key.ToString(), driver);
break;
case "hibernate.dialect":
dir.Add(de.Key.ToString(), dialect);
break;
case "hibernate.connection.provider":
dir.Add(de.Key.ToString(),"NHibernate.Connection.DriverConnectionProvider");
break;
}
}

config.Properties = dir;
config.AddAssembly("Business");

return config.BuildSessionFactory().OpenSession();

}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 9:59 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
My usual solution to this is to actually have two different SessionFactory objects configured from different sections in the web.config. Each SessionFactory would be connected to different databases - one to Access, the other the SQL Server.

Then you can move the objects between the sessions for each SessionFactory by evicting from the source Session and then using SaveOrUpdate on the destination Session (depending on what you're trying to do, of course).

Cheers,

Symon.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.