Data Access not respecting commandTimeout setting

5 posts, 2 answers
  1. margan
    margan avatar
    17 posts
    Member since:
    Oct 2010

    Posted 08 Oct 2014 Link to this post

    Hi,

    I've added to my configuration those lines (using oracle):

     <section name="openAccessConfiguration" type="Telerik.OpenAccess.Config.OpenAccessConfigSectionHandler, Telerik.OpenAccess" requirePermission="false" />

    <openAccessConfiguration>
        <backendConfiguration name="ReportsConfiguration" backend="Oracle">
          <runtime commandTimeout="6000"></runtime>
        </backendConfiguration>
      </openAccessConfiguration>

    In code I've also added this:

    BackendConfiguration fromCodeConfiguration =EntitiesModel.GetBackendConfiguration();
    BackendConfiguration.MergeBackendConfigurationFromConfigFile(fromCodeConfiguration, ConfigurationMergeMode.ConfigFileDefinitionWins, "ReportsConfiguration");
               
    Logger.Info(string.Format("CommandTimeout chenged to {0}", fromCodeConfiguration.Runtime.CommandTimeout));
    using (EntitiesModel dbContext = new EntitiesModel(fromCodeConfiguration))
    ...
     var result = dbContext.ExecuteQuery<Reports_Classes.IloscWKategoriachData>(query).ToList();
    ...

    In my logger I see that fromCodeConfiguration.Runtime.CommandTimeout shows 6000 but nevertheless I'm still getting error "user requested cancel operation" after 30seconds.

    What else I should do to make it work?

    Regards,
    Sebastian

  2. Answer
    Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 13 Oct 2014 Link to this post

    Hello Sebastian,

    I am sorry to hear that you are experiencing issues when performing queries with Telerik Data Access.
    I have tried and failed to reproduce the same command timeout in our test suite. The configured value (6000 seconds) was properly set to the underlying DbCommand instance.

    Are you using a different backend configuration in other places in your application?
    If you are you should know that there is an internal Database object instance that is created the first time you have created a OpenAccessContext instance and the backend configuration provided at that point is the one that will be used for the whole lifetime of the Database object. 
    One easy way to fix the issue in that case is just to apply the configuration during your application start-up.
    Another option is to have two separate Database instances running in parallel and using different configurations - one with original start-up settings and one with new report-friendly. One easy way to create a new Database object is to use the following code:
    01.// extend your context class via a partial class
    02.public partial class EntitiesModel
    03.{
    04.    public EntitiesModel(string cacheKey, BackendConfiguration backendConfig)
    05.        : base(connectionStringName, cacheKey, backendConfig, metadataSource)
    06.    {
    07.    }
    08.}
    09. 
    10.// in your query method use the new constructor
    11.BackendConfiguration fromCodeConfiguration = EntitiesModel.GetBackendConfiguration();
    12.BackendConfiguration.MergeBackendConfigurationFromConfigFile(fromCodeConfiguration,
    13.                      ConfigurationMergeMode.ConfigFileDefinitionWins,
    14.                      "ReportsConfiguration");
    15.using (var context = new EntitiesModel("ReportsConfigurationDbConfig", fromCodeConfiguration))
    16.{
    17.    // TODO: perform your query
    18.}

    This code snippet will result in creation of a new Database object instance with the specified configuration. The cacheKey ("ReportsConfiguraitonDbConfig" in the example) will allow you to reuse the second Database instance the next time you are using this code. 
    Please note that Database object creation is a costly operation and will result in higher memory consumption. You should fine the best balance between keeping more than one instance active and creating/disposing the extra one(s) after you are done with them.
    In order to dispose your existing database instance you can use OpenAccessContext.DisposeDatabase(string) method as described on the bottom of this page.

    If you are still having trouble with command timeout errors while running your query, please let us know and we will arrange a way for you to send us your model and the query code if it is possible.

    Regards,
    Viktor Zhivkov
    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. margan
    margan avatar
    17 posts
    Member since:
    Oct 2010

    Posted 14 Oct 2014 in reply to Viktor Zhivkov Link to this post

    Hi Viktor,

    Thanks for replay.

    This is the first time that I want to change the backend configuration in code in other queries the default 30 seconds is ok.
    I just thought I could change this by applying this backend config every time I need to on query.

    Could you please tell me if I'm getting this right:
    1. Database object is created when I create the first Entity model on new EntitiesModel constructor in my code.
    2. Database object persists for the whole lifetime of application even when the EntityModel is destroyed by using statement.
    3. Every user of application uses the same database object with the same backend configuration which is created only once.

    Regardless my questions, I have tried to use your solution.
    I had to increase my setting for the AsyncPostBackTimeout of the update panel.
    I don't see cancelation error anymore but now I'm getting Thread Was being aborted after 5 minutes from executing query.

    Could you please advise something?

    Regards,
    Sebastian

  5. Answer
    Viktor Zhivkov
    Admin
    Viktor Zhivkov avatar
    291 posts

    Posted 14 Oct 2014 Link to this post

    Hi Sebastian,

    You can find my answers to your questions here:
    1. Database object is created when I create the first Entity model on new EntitiesModel constructor in my code - YES - a new Database object will be created if you change either your cacheKey or connectionString.
    2. Database object persists for the whole lifetime of application even when the EntityModel is destroyed by using statement. - YES - you can destroy the underlying Database object by calling context.DisposeDatabase("") or by unloading your application/application domain.
    3. Every user of application uses the same database object with the same backend configuration which is created only once. - YES - this is the default behavior, you can modify that by using different cacheKey or connectionString values.
    Regarding any Thread Aborted errors I believe you may have to change some ASP.NET Request timeout settings (if you are in Web Application scenario) and to modify the connection timeout on Telerik Data Access level.
    You have to make Active Connection Timeout value greater than the Command Timeout value you are setting otherwise the command will be able to wait for quite some time, but the connection will get closed prematurely and fail the whole operation.
    Here is excerpt of our documentation describing the setting:
    • ActiveConnectionTimeout - sets the number of seconds after which, active connections that have been inactive or busy are closed. The default value is 120 seconds. If you need connections to remain open for an unlimited timespan (until the OpenAccessContext.Dispose() method is called), you should set the connection timeout to 0. 
    Please check the article how to set this backend configuration setting either by code or via the app/web.config file.

    As rule of thumb you should keep this ratio in you timeout settings:
    Command Timeout < Connection Timeout < Request Timeout
    You may even make the request timeout a few times larger than the maximum Connection Timeout to be able to accommodate several long running operations.

    Regards,
    Viktor Zhivkov
    Telerik
     
    OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
     
  6. margan
    margan avatar
    17 posts
    Member since:
    Oct 2010

    Posted 15 Oct 2014 Link to this post

    Hi Viktor,

    Now it works quite nice after applying all your suggestions.

    Many thanks for your help.
    Regards,
    Sebastian
Back to Top
DevCraft banner