调用POST-OData服务超时触发连接强制关闭报错排查请求
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:
- Open IIS Manager, navigate to your site.
- Go to Advanced Settings > Connection Timeout and set it to a value larger than 60 seconds (e.g., 120 seconds).
- 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

