You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调用POST-OData服务超时触发连接强制关闭报错排查请求

Fixing "An existing connection was forcibly closed by the remote host" for Long-Duration OData POST Requests

Alright, let's break down this issue: your OData POST call succeeds if you submit data within 1 minute, but throws a connection closure error when input takes longer. The root cause here is almost certainly timeout mismatches across your frontend, backend OData service, and SQL Server. Here are the step-by-step fixes you can implement:


1. Adjust Frontend AJAX Timeout

By default, jQuery's $.ajax uses the browser's default timeout (often around 60 seconds). Since your input process can take longer than that, explicitly set a longer timeout in your request:

$.ajax({
    "url": "/Non_SAP_Instrumentation/odata/LoopDrawing",
    "method": "POST",
    "timeout": 120000, // Set to 2 minutes (120,000 milliseconds) - adjust as needed
    "data": {
        "UnitNumber": unit_no,
        "TagName": tag_name,
        "SysTagName": sys_tag_name,
        "TagDesc": tag_description,
        "JbNo": jb_no,
        "JbPairNo": jb_pair_no,
        "JbTerminal": jb_terminal,
        "IoType": io_type,
        "Ctrl": controller,
        "Node": node,
        "Slot": slot,
        "Channel": channel,
        "Segment": segment,
        "Redundancy": redundancy,
        "MarCab": marsh_cab,
        "SurgeProtc": surge_protc,
        "Barrier": barrier,
        "Relay": relay,
        "FuseTbGrp": fuse_tb_group,
        "FuseTbTerm": fuse_tb_term,
        "Update": "No",
        "CreatedBy": that.name,
        "CreatedByID": that.EmpModel.getProperty("/").name,
        "ModifiedBy": that.name,
        "ModifiedByID": that.EmpModel.getProperty("/").name
    },
    "dataType": "json",
    "success": function(data) {
        var value = JSON.parse(data.value);
        sap.ui.core.BusyIndicator.hide();
        if (value.Status == "OK") {
            MessageBox.information("Loop Drawing has been created", {
                "onClose": function() {
                    that.router.navTo("TagMasterPage", { "TAG": tag_name });
                    that.makingFieldsBlank();
                    that.window.location.reload();
                }
            });
        } else {
            sap.ui.core.BusyIndicator.hide();
            MessageBox.information("Unable to create Loop Drawing", {
                "onClose": function() {
                    that.router.navTo("SearchOrCreate");
                    that.window.location.reload();
                }
            });
        }
    },
    "error": function(err) {
        sap.ui.core.BusyIndicator.hide();
        console.log(err.responseText);
        MessageBox.information("Unable to create Loop Drawing", {
            "onClose": function() {
                that.router.navTo("SearchOrCreate");
            }
        });
    }
})

2. Configure Backend OData Service Timeouts

If your OData service is hosted on ASP.NET (a common setup), update these settings in your web.config:

  • HttpRuntime Execution Timeout: Controls how long an ASP.NET request can run before being terminated.
    <system.web>
        <httpRuntime executionTimeout="120" /> <!-- 120 seconds = 2 minutes -->
    </system.web>
    
  • Entity Framework Command Timeout: If your service uses EF to interact with SQL Server, set a longer timeout for database operations:
    // In your DbContext initialization
    public YourDbContext() : base("YourConnectionString")
    {
        this.Database.CommandTimeout = 120; // 2 minutes
    }
    

3. Adjust SQL Server Timeout Settings

Check if SQL Server is terminating the connection prematurely:

  • Remote Query Timeout: Run this query in SQL Server Management Studio to increase the timeout for remote queries (if applicable):
    sp_configure 'remote query timeout', 120; -- 120 seconds
    RECONFIGURE;
    
  • Query Timeout for Specific Operations: If your OData service calls stored procedures or long-running queries, ensure those operations don't have hardcoded short timeouts.

4. Check IIS (If Hosted) Connection Timeouts

If your OData service is hosted on IIS:

  1. Open IIS Manager, navigate to your site.
  2. Go to Advanced Settings > Connection Timeout and set it to a value larger than 60 seconds (e.g., 120 seconds).
  3. For your application pool, go to Advanced Settings > Idle Timeout and increase it to match your expected maximum request duration.

Bonus: Optimize Input Workflow

While fixing timeouts will resolve the immediate error, consider optimizing your frontend input flow to avoid holding the connection open unnecessarily:

  • Let users save a draft of their input first, then submit it in one go once all fields are filled.
  • Disable auto-save or partial submission logic that might keep connections hanging.

内容的提问来源于stack exchange,提问作者Swappy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 07:59:46