在httprequest CLR C#中隐藏超时错误

时间:2015-12-09 17:00:47

标签: c# sql-server clr sqlclr

我有代码C#(CLR):

var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://sitewait10seconds.com/script.php?param=1");
httpWebRequest.Method = "GET";
httpWebRequest.Timeout = 30;
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
httpWebRequest.Abort();
httpResponse.Close();

我在循环中调用此CLR并且我想在调用script.php之后关闭连接,因为我不需要任何响应,我想用下一个参数调用此CLR。 我设置了

httpWebRequest.Timeout = 30; 

但是我收到了错误

A .NET Framework error occurred during execution of user-defined routine or aggregate "myProcedure": 
System.Net.WebException: The operation has timed out
System.Net.WebException: 
at System.Net.HttpWebRequest.GetResponse()
at StoredProcedures.InsertCurrency_CS(.....

是否有任何选项可以隐藏此消息并让此代码继续使用?

1 个答案:

答案 0 :(得分:-1)

您可以忽略特定的异常,如下所示:

try
{
    // do something
}
catch (Exception ex)
{
    if (ex.Message.Contains("The operation has timed out")) return;
}