Data Controllers / Framework
Increasing Command Timeout

Commands issued by the application framework use a default timeout of 30 seconds. When necessary, this timeout can be changed to fit application requirements.

Let’s change the default command timeout to 5 minutes.

Start Code On Time web application generator, and click on the project name. Then, click on Develop option. The project will be opened in Visual Studio.

In the Solution Explorer, right-click on ~\App_Code folder and press Add | Add New Item.

Adding a new item under 'App_Code' folder in the project.

Select Class from the list and press Add to create the file. Replace the code with the following:

C#:

using System;
using System.Data.Common;

namespace MyCompany.Data
{
    public partial class Controller
    {
        protected override DbCommand CreateCommand(DataConnection connection)
        {
            DbCommand command = base.CreateCommand(connection);
            command.CommandTimeout = 60 * 5;
            return command;
        }
    }
}

Visual Basic:

Imports Microsoft.VisualBasic
Imports System
Imports System.Data.Common

Namespace MyCompany.Data
    Partial Public Class Controller
        Protected Overrides Function CreateCommand(connection As DataConnection) As DbCommand
            Dim command As DbCommand = MyBase.CreateCommand(connection)
            command.CommandTimeout = 60 * 5
            Return command
        End Function
    End Class
End Namespace

Save the file.

Let’s make sure that the application uses the new command timeout. Place a breakpoint at the last line in the method, and press F5 key to run the web app.

Placing a breakpoint in the class.

Navigate to any page that has a data view. The application will stop at the breakpoint. Mouse over the command timeout property – the value will now be “300”.

The value of 'CommandTimeout' property has been changed.