Back to Devexpress

Manage Timeout Limit

dashboard-403165-winforms-dashboard-winforms-designer-create-dashboards-in-the-winforms-designer-providing-data-sql-data-source-manage-timeout-limit.md

latest3.5 KB
Original Source

Manage Timeout Limit

  • Jun 02, 2021
  • 2 minutes to read

The Dashboard Designer has a 300-second time limit to execute a query. When a query timeout expires, the query execution stops and an exception occurs.

You can extend or shorten the time limit in code. The ConnectionOptions.DbCommandTimeout property specifies how many seconds the Dashboard Designer waits for a query to execute. The time set in the property is stored in a dashboard definition after a successful connection to a database.

The example below shows how to extend the timeout.

The created SetTimeout method sets the time limit up to 600 seconds for each SQL Data Source in the current Dashboard. When the DashboardDesigner.DashboardChanged and Dashboard.DataSourceCollectionChanged events occur, the SetTimeout is called.

csharp
using DevExpress.DashboardCommon;
using DevExpress.DataAccess.Sql;
using System;
using System.Windows.Forms;

namespace DesignerSample {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
            dashboardDesigner1.CreateRibbon();
            dashboardDesigner1.DashboardChanged += dashboardDesigner1_DashboardChanged;
        }
        private void dashboardDesigner1_DashboardChanged(object sender, EventArgs e) {
            SetTimeout();
            dashboardDesigner1.Dashboard.DataSourceCollectionChanged += Dashboard_DataSourceCollectionChanged;
        }

        void Dashboard_DataSourceCollectionChanged(object sender, DevExpress.DataAccess.NotifyingCollectionChangedEventArgs<IDashboardDataSource> e) {
            SetTimeout();
        }

        private void SetTimeout() {
            foreach(var dataSoure in dashboardDesigner1.Dashboard.DataSources) {
                if(dataSoure is SqlDataSource) {
                    (dataSoure as SqlDataSource).ConnectionOptions.CommandTimeout = 600;
                }
            }
        }

    }
}
vb
Imports DevExpress.DashboardCommon
Imports DevExpress.DataAccess.Sql
Imports System
Imports System.Windows.Forms

Namespace DesignerSample
    Partial Public Class Form1
        Inherits Form
        Private Function Form1() As Public
            InitializeComponent()
            dashboardDesigner1.CreateRibbon()
            AddHandler dashboardDesigner1.DashboardChanged, AddressOf dashboardDesigner1_DashboardChanged
        End Function
        Private Sub dashboardDesigner1_DashboardChanged(ByVal sender As Object, ByVal e As EventArgs)
            SetTimeout()
            AddHandler dashboardDesigner1.Dashboard.DataSourceCollectionChanged, AddressOf Dashboard_DataSourceCollectionChanged
        End Sub

        Private Sub Dashboard_DataSourceCollectionChanged(ByVal sender As Object, ByVal e As DevExpress.DataAccess.NotifyingCollectionChangedEventArgs(Of IDashboardDataSource))
            SetTimeout()
        End Sub

        Private Sub SetTimeout()
            For Each dataSoure In dashboardDesigner1.Dashboard.DataSources
                If TypeOf dataSoure Is SqlDataSource Then
                    TryCast(dataSoure, SqlDataSource).ConnectionOptions.CommandTimeout = 600
                End If
            Next dataSoure
        End Sub
    End Class
End Namespace