Increase timeout for editor DtResponse

Increase timeout for editor DtResponse

SAM ITSAM IT Posts: 3Questions: 1Answers: 0

Hi,

I am using datatable editor. Currently the response will return timeout after 30 seconds.
If we use query, we can set the command timeout for the specific command to certain time (example 1 min).
So may I know if it is possible to increase the timeout for specific request for datatable editor.

           var settings = Properties.Settings.Default;
           var formData = HttpContext.Request.Form;

            var conn = ConfigurationManager.ConnectionStrings[settings.DbConnection].ConnectionString;
            using (var db = new DataTables.Database(settings.DbType, conn))
            {

                var response = new Editor(db, "VW000RPTConsignmentTbl", new[] { "CustomerCode", "DeliveryCode", "MaterialCode", "Batch", "SerialNo" })
                   .Model<VW000RPTConsignmentTbl>()
                    .Where(q =>
                    {
                        if (string.IsNullOrEmpty(materialcode)) return;
                        q.Where("MaterialCode", materialcode);
                    })
                    .Process(formData)
                    .Data();


                JsonNetResult jsonNetResult = new JsonNetResult();
                jsonNetResult.Formatting = Formatting.Indented;
                jsonNetResult.Data = response;

                return jsonNetResult;
            }

Thanks and best regards.

Answers

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Hi,

    We basically pass the ajax object through to jQuery, so you can use the jQuery options as well - e.g.:

    ajax: {
      url: ...,
      timeout: 60
    }
    

    Allan

  • SAM ITSAM IT Posts: 3Questions: 1Answers: 0

    Hi,

    After I add timeout, the table just keep on loading. However when I debug, the server successfully passing back records. Below is how I Initialise the table.

    var oTable = $('#datatab').DataTable({
                    "scrollX": true,
                    "autoWidth": true,
                    "processing": true,
                    "ajax": {
                        "url": "@Url.Action("TableConsignment", "Report")",
                        "type": "POST",
                        "timeout": 60,
                        "data": function (d) {
                            d.materialcode = document.getElementById("txtMaterialCode").value;
                        }
                    },
                    "iDisplayLength": 50,
                    "dom": 'Blrt<"row"<"col-sm-5"i><"col-sm-7"p>>',
                    "columns": [
                       {
                           "data": "ClientCode"
                       },
    
  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Are you able to give me a link to the page so I can take a look please?

    Thanks,
    Allan

  • SAM ITSAM IT Posts: 3Questions: 1Answers: 0

    Hi Allan,

    I am sorry but I am unable to provide you with the link. Just For confirmation, if I set the timeout in ajax, the request should follow the timeout set in ajax? For example if I use sql command, I can set it as below.

    using (SqlConnection conn= new SqlConnection(connectionString)) {  
             conn.Open();  
             SqlCommand command = new SqlCommand(queryString, conn);  
             // Setting command timeout to 60 second  
             command.CommandTimeout = 60;  
    
    List<VW000RPTConsignmentTbl> material = conn.Query<VW000RPTConsignmentTbl>(selectSql,
                            new
                            {
                                MaterialCode =  materialcode
                            }, commandTimeout: 60).ToList();
    
  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin

    Just For confirmation, if I set the timeout in ajax, the request should follow the timeout set in ajax?

    Setting:

    ajax: {
      url: ...,
      timeout: 60,
      ...
    }
    

    means the client-side will give the server 60 seconds to response. If it doesn't then the client-side will terminate the connection and throw an error.

    If you wanted to add a similar timeout to the SQL command then absolutely you could do that. That makes no difference to DataTables.

    Allan

This discussion has been closed.