在 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 中运行缓慢
发布评论