There are open context instances.

4 posts, 0 answers
  1. Dave
    Dave avatar
    4 posts
    Member since:
    May 2013

    Posted 09 Jun 2014 Link to this post

    I am running this on an Azure site which has two webjobs.  Has one one seen this error and how to address it?  It basically makes my site time out when it occurs.

    There are open context instances. This can happen if properties and events that affect the context behavior such as those defined in - 'IOpenAccessContextOptions' or 'IContextEvents' interfaces, are set prior to executing DDL operations. DDL operations should only be executed exclusively. Use force to override this configuration.

    regards,
    D
  2. Kaloyan Nikolov
    Admin
    Kaloyan Nikolov avatar
    118 posts

    Posted 12 Jun 2014 Link to this post

    Hi Dave,

    The schema changes usually require exclusive lock over the database. In case there are open connections you would see the exception you mention. You can avoid the problem by calling the ForceExecuteDDL method instead of the ExecuteDDL. Then the schema change will be done without the exception but the other clients that might be connected in the same time will experience time outs  because of the locks. In general if the change doesn't affect the tables that are in use at the moment you will not have such problems. 

    However it is not recommended to deliver schema changes in working site if you cannot hold down the connections for a while. I would suggest you to implement special handling for such updates. You can delay the requests or serve a special page to the users to inform them that an upgrade is in progress and they are kindly asked to come back in a minute. 

    I hope this helps. Should you have any additional questions do not hesitate to get back to us.

    Regards,
    Kaloyan Nikolov
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  3. DevCraft banner
  4. Richard
    Richard avatar
    2 posts
    Member since:
    Apr 2013

    Posted 22 Jul 2014 in reply to Kaloyan Nikolov Link to this post

    Hello,

    I was updating the application in my production environment when suddenly this began happening to me. So I've also now rolled back by restoring my database from test, and also completely restoring the application and now it's happening there too. But the copy from test is actively running and has no problems. Identically application and database and very rare error? (or some silly mistake on my part). It is despairatic though because initially setting up the production was a breeze. But now can't do anything in production till this error goes away. 
  5. Kaloyan Nikolov
    Admin
    Kaloyan Nikolov avatar
    118 posts

    Posted 24 Jul 2014 Link to this post

    Hi Richard,

    Usually such problems could occur after a previews code change which has imposed one of the following things:
    1. You have a long running queries that are executed relatively often 
    2. The schema migration is not the first operation with the DB when your app starts any more. 
    3. You have switched from short living to long living contexts and thus the scope is left open for longer time.

    I would suggest you to check if the schema migration is the first thing which happens in your app when it starts, if it is not - prevent any other previous DB operations.
    Also you could retry the schema migration in case of this exception several times to find a moment when there is no currently executing query. You can sleep random time interval between the retries. In case you exceed the allowed retries you could give up or use the ForceExecuteDDL method which will execute the script regardless if there are running queries or not but you should know that this could cause errors in such running queries. 

    As a bottom line I would say that your application logic should ensure that when you perform the schema migration not other DB operations are running. 

    I hope this helps.

    Regards,
    Kaloyan Nikolov
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
Back to Top