Question

I have a web service implemented in ASP.NET.

I instantiate my NHibernate session in the Global.asax event handlers as follows:

    protected void Application_BeginRequest(object sender, EventArgs e)
    {
        NHibernateInitializer.Instance().InitializeNHibernateOnce(
        () => InitializeNHibernateSession());
    }

    private void InitializeNHibernateSession()
    {
        NHibernateSession.Init(
            webSessionStorage,
            new string[] { Server.MapPath("~/bin/DAL.Server.Data.dll") },
            new AutoPersistenceModelGenerator().Generate(),
            Server.MapPath("~/NHibernate.config"));
    }

My problem is, whenever I need to update the NHibernate.config connection string to connect to a different database (for testing purpose, on the deployment server) NHibernate still maintain the connection to the previously connected DB.

Only restarting IIS can resolve this problem. Does anyone have any idea if this is due to come kind of caching in IIS? or some settings I have missed out? Thanks in advance!

Was it helpful?

Solution

Change in nhibernate.config file does not force restart of IIS application, that means that it keeps working with the same istance of ISessionFactory and IOC container configured.

The best is to configure nhibernate to use connection string that is stored in web.config file and referenced by name.

Another thing you can do is to move configuration of nhibernate into web.config file. Then chagning it would force reconfiguration of nhibernate.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top