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();
}
|