Data Access has been discontinued. Please refer to this page for more information.

How to: Set The Command Timeout

This article will give you details about how you can set the timeout for the execution of all Telerik Data Access operations:

On Global Level

On global level, the timeout for all Telerik Data Access operations can be set either through The Backend Configuration Of The Model or in the app.config/web.config file of the project that holds the model.

Through The Backend Configuration Of The Model

Consider the SofiaCarRental model. The timeout setting can be applied with the help of the following steps:

  1. Open the FluentModel file that holds the context.
  2. Locate the GetBackendConfiguration method, which provides the backend object consumed by the context.
  3. In it, adjust the value of the command timeout through the Runtime.CommandTimeout property.

    public static BackendConfiguration GetBackendConfiguration()
        BackendConfiguration backend = new BackendConfiguration();
        backend.Backend = "MsSql";
        backend.ProviderName = "System.Data.SqlClient";
        backend.Runtime.CommandTimeout = 100;
        CustomizeBackendConfiguration(ref backend);
        return backend;
    Public Shared Function GetBackendConfiguration() As BackendConfiguration
        Dim backend As BackendConfiguration = New BackendConfiguration()
        backend.Backend = "MsSql"
        backend.ProviderName = "System.Data.SqlClient"
        backend.Runtime.CommandTimeout = 100
        Return backend
    End Function
  4. Save the FluentModel file.

In The Config File

Setting the timeout value in the app.config/web.config file can be achieved with the following process:

  1. Open the app.config/web.config file of the application.
  2. In the <configuration> section, create a new section called openAccessConfiguration:

        <section name="openAccessConfiguration"
                 type="Telerik.OpenAccess.Config.OpenAccessConfigSectionHandler, Telerik.OpenAccess"
                 requirePermission="false" />
  3. Set the timeout value in the new section as shown below:

          <backendConfiguration name="MyBackendConfiguration" backend="MsSql">
            <runtime commandTimeout="100"></runtime>
  4. Save the app.config/web.config file.

  5. The setting can be consumed like this:
BackendConfiguration fromCodeConfiguration = 
using (FluentModel dbContext = new FluentModel(fromCodeConfiguration))
        //a Telerik Data Access Operation
Dim fromCodeConfiguration As BackendConfiguration =  _
BackendConfiguration.MergeBackendConfigurationFromConfigFile(fromCodeConfiguration, _
Using dbContext As New FluentModel(fromCodeConfiguration)
        'a Telerik Data Access Operation
End Using

On Query Level

By design, Telerik Data Access will respect the timeout value on query level, if it is provided. In every other case, it will take into account the global one.

The following example demonstrates how to specify a timeout value on query level:

using Telerik.OpenAccess;
using (FluentModel dbContext = new FluentModel())
    List<Car> allCars = dbContext.Cars
                        .WithOption(new QueryOptions ()
                            CommandTimeout = 100 //in seconds
Imports Telerik.OpenAccess
Using dbContext As New FluentModel()
    Dim allCars As List(Of Car) = dbContext.Cars.
        WithOption(New QueryOptions() With
                       .CommandTimeout = 100 'in seconds
End Using

The WithOption() extension method resides in the Telerik.OpenAccess namespace

If a given Telerik Data Access operation exceeds the timeout value, a backend specific exception with the following text will be thrown:

Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.