This is a migrated thread and some comments may be shown as answers.

There are open context instances.

3 Answers 92 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dave
Top achievements
Rank 1
Dave asked on 10 Jun 2014, 03:46 AM
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

3 Answers, 1 is accepted

Sort by
0
Kaloyan Nikolov
Telerik team
answered on 12 Jun 2014, 04:25 PM
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.
 
0
Richard
Top achievements
Rank 1
answered on 22 Jul 2014, 10:22 PM
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. 
0
Kaloyan Nikolov
Telerik team
answered on 24 Jul 2014, 08:38 AM
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.
 
Tags
General Discussions
Asked by
Dave
Top achievements
Rank 1
Answers by
Kaloyan Nikolov
Telerik team
Richard
Top achievements
Rank 1
Share this question
or