Results 1 to 4 of 4

Thread: Exception on startup when DB is unavailable.

  1. #1
    Join Date
    Jul 2009
    Posts
    54

    Default Exception on startup when DB is unavailable.

    I have a background Windows Service that polls the database and executes background jobs, the problem is that when I startup the service and the DB is unavailable the Windows Service will not start correctly because nHibnerate is trying to connect to the DB for some reason at startup - not 100% sure why.

    How do I adjust this so that nHibernate does not try to connect to the database upon startup - that way when the database does eventually become available and the polling will then connect and grab a job to execute.

    Thanks in advance.

    Whatty

  2. #2
    Join Date
    Aug 2005
    Location
    Tampere, Finland
    Posts
    161

    Default

    I believe this is because NHibernate connects to DB to check quoting configuration. http://fabiomaulo.blogspot.fi/2009/0...umn-names.html . What you want is to set is in configuration:

    <property name="hbm2ddl.keywords">none</property>

    Or by code:

    properties.Add(Environment.Hbm2ddlKeyWords, "none");

  3. #3
    Join Date
    Jul 2009
    Posts
    54

    Default

    First of all thanks for the response.

    I gave that a shot with no success - in fact it doesn't seem to make a difference in the behaviour on startup (I setup a SQL trace and could not find anything obvious)

    It is definitely trying to open a connection to the database on startup (or to be more precise nHibnerate object initialization) - as far as I can tell it is the open connection that is causing the problem - since when the DB is not available, the nHibernate object creation fails which then causes Spring initialization to fail

    Spring.Objects.Factory.Support.DefaultListableObje ctFactory 2014-11-22 15:50:14,881 ERROR [4] - GetObjectInternal: error obtaining object PureWMS_SessionFactory
    Spring.Objects.Factory.Support.DefaultListableObje ctFactory 2014-11-22 15:50:14,966 ERROR [4] - GetObjectInternal: error obtaining object securityEventDAO
    Spring.Objects.Factory.Support.DefaultListableObje ctFactory 2014-11-22 15:50:14,978 ERROR [4] - GetObjectInternal: error obtaining object securityHandler
    Spring.Objects.Factory.Support.DefaultListableObje ctFactory 2014-11-22 15:50:14,988 ERROR [4] - GetObjectInternal: error obtaining object securityPointcut
    Spring.Objects.Factory.Support.DefaultListableObje ctFactory 2014-11-22 15:50:15,000 ERROR [4] - GetObjectInternal: error obtaining object ProxyCreator

    where PureWMS_SessionFactory

    <object id="PureWMS_SessionFactory" type="Spring.Data.NHibernate.LocalSessionFactoryOb ject">

    is the standard hNibernate LocalSessionFactoryObject configuration.

    I can probably get around this by purposely sitting on the Spring context initialization and catching this type of exception and re-trying in a wait loop but that seems like a lot of work for something that I believe should already be handled by nHibernate

    Any further assistance would be greatly appreciated.

  4. #4
    Join Date
    Aug 2005
    Location
    Tampere, Finland
    Posts
    161

    Default

    I tried locally with the "none" setting and got my app starting nicely without SQL Server running. I'd suspect that your culprit might be in the securityEventDAO, is it loading something? I'd suggest you to run the program under Visual Studio with break on all exceptions and you might get the correct stack trace about who's initiating the first database call.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •