You can not change the assembly of a session. This would allow as session to do an ‘expensive’ job that you want to do only once when creating the NHibernate Configuration. However, it is possible to change the connection properties of a Configuration and then get a new session from its session factory, so you don't have to change the session's connection properties.
We did this in a small conversion project where we had to move data from one database to another, hope this snippet will help:
this._cfg.Properties.Clear();
this._cfg.Properties.Add("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider");
switch (provider)
{
case Provider.MsSql2000:
this._cfg.Properties.Add("hibernate.dialect", "NHibernate.Dialect.MsSql2000Dialect");
this._cfg.Properties.Add("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver");
this._cfg.Properties.Add("hibernate.connection.connection_string", connectionString);
break;
case Provider.MsAccess:
this._cfg.Properties.Add("hibernate.dialect","NHibernate.JetDriver.JetDialect, NHibernate.JetDriver");
this._cfg.Properties.Add("hibernate.connection.driver_class", "NHibernate.JetDriver.JetDriver, NHibernate.JetDriver");
string conString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + connectionString;
this._cfg.Properties.Add("hibernate.connection.connection_string", conString);
break;
}
where _cfg is a singleton NHibernate Configuration instance.
|