HttpWebRequest 第一次在 SQLCLR 中运行缓慢

编程入门 行业动态 更新时间:2024-10-26 11:21:42
本文介绍了HttpWebRequest 第一次在 SQLCLR 中运行缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在 CLR 存储过程中创建 HttpWebRequest 时(按照下面的代码),在(重新)启动 Sql Server 之后或在给定(但不确定)的时间段之后的第一次调用将等待相当长的时间GetResponse() 方法调用的时间.

When making an HttpWebRequest within a CLR stored procedure (as per the code below), the first invocation after the Sql Server is (re-)started or after a given (but indeterminate) period of time waits for quite a length of time on the GetResponse() method call.

是否有任何不涉及黑客"的方法来解决此问题?例如每隔几分钟运行一次 Sql Server 代理作业,以尝试确保第一个慢"呼叫是由代理发出的而不是真实的"生产代码?

Is there any way to resolve this that doesn't involve a "hack" such as having a Sql Server Agent job running every few minutes to try and ensure that the first "slow" call is made by the Agent and not "real" production code?

function SqlString MakeWebRequest(string address, string parameters, int connectTO) { SqlString returnData; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(String.Concat(address.ToString(), "?", parameters.ToString())); request.Timeout = (int)connectTO; request.Method = "GET"; using (WebResponse response = request.GetResponse()) { using (Stream responseStream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(responseStream)) { SqlString responseFromServer = reader.ReadToEnd(); returnData = responseFromServer; } } } response.Close(); return returnData; }

(为简洁起见,错误处理和其他非关键代码已被删除)

(Error handling and other non-critical code has ben removed for brevity)

另见 此 Sql Server 论坛主题.

推荐答案

这是我最初使用 HttpWebRequest 时遇到的问题.这是由于该类正在寻找要使用的代理.如果您将对象的 Proxy 值设置为 null/Nothing,它会直接压缩.

This was a problem for me using HttpWebRequest at first. It's due to the the class looking for a proxy to use. If you set the object's Proxy value to null/Nothing, it'll zip right along.

更多推荐

HttpWebRequest 第一次在 SQLCLR 中运行缓慢

本文发布于:2023-11-16 17:10:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1606225.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓慢   HttpWebRequest   SQLCLR

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!