C# 不存在从对象类型System.Net.Sockets.SocketException到已知托管提供程序本机类型的映射

C# 不存在从对象类型System.Net.Sockets.SocketException到已知托管提供程序本机类型的映射,c#,html-agility-pack,socketexception,C#,Html Agility Pack,Socketexception,我已经创建了一个网页,能够发布一些价值到其他网站,并得到作为HTML文档从该页面的响应。在我从另一个网站得到响应后,我将在HTMLAgilityPack的帮助下解析它,并获取所需的数据。然后,这些数据保存在SQL Server数据库中。这种“全部”方案在开发环境中运行良好,但在服务器上部署后,它会出现上述错误 这里是我从其他网站获取数据、解析和保存数据的函数 public static string FetchDataFromWebsite(string uId) { s

我已经创建了一个网页,能够发布一些价值到其他网站,并得到作为HTML文档从该页面的响应。在我从另一个网站得到响应后,我将在HTMLAgilityPack的帮助下解析它,并获取所需的数据。然后,这些数据保存在SQL Server数据库中。这种“全部”方案在开发环境中运行良好,但在服务器上部署后,它会出现上述错误

这里是我从其他网站获取数据、解析和保存数据的函数

public static string FetchDataFromWebsite(string uId)
    {
        string url = "http://demourl.aspx";
        var encoding = new ASCIIEncoding();
        string postData = "some data to post";
        byte[] data = encoding.GetBytes(postData);

        var myRequest = (HttpWebRequest)WebRequest.Create(url);
        myRequest.Method = "POST";
        myRequest.ContentType = "application/x-www-form-urlencoded";
        myRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; sv-SE; rv:1.9.1b2) Gecko/20081201 Firefox/3.1b2";
        myRequest.ContentLength = data.Length;
        var newStream = myRequest.GetRequestStream();
        newStream.Write(data, 0, data.Length);
        newStream.Close();

        var response = myRequest.GetResponse();
        var responseStream = response.GetResponseStream();
        var responseReader = new StreamReader(responseStream);
        var result = responseReader.ReadToEnd();

        HtmlDocument doc = new HtmlDocument();
        doc.LoadHtml(result);

        var table = doc.DocumentNode.SelectSingleNode("//*[@id='GridView1']");
        if (table != null)
        {
            var tr = table.SelectSingleNode("//tr[2]");
            string[] trData = new string[12];

            int rowCount = 0;

            foreach (HtmlNode td in tr.SelectNodes("//td"))
            {
                rowCount++;
                if (rowCount > 3 && rowCount < 16)
                {

                    trData[rowCount - 4] = td.InnerText;
                }
                if (rowCount >= 16)
                {
                    break;
                }
            }
            saveDataInDatabase(trData);
            return "Cheers! data saved.";

        }
        else
        {

            var span = doc.DocumentNode.SelectSingleNode("//span[@id='lbmessage']");
            string message = span.InnerText;
            InsertErrorLog(uId, message);
            return "No data found";
        }
}
publicstaticstringfetchdatafromwebsite(stringuid)
{
字符串url=”http://demourl.aspx";
var encoding=new ascienceoding();
string postData=“要发布的某些数据”;
byte[]data=encoding.GetBytes(postData);
var myRequest=(HttpWebRequest)WebRequest.Create(url);
myRequest.Method=“POST”;
myRequest.ContentType=“application/x-www-form-urlencoded”;
myRequest.UserAgent=“Mozilla/5.0(Windows;U;Windows NT 6.0;sv SE;rv:1.9.1b2)Gecko/20081201 Firefox/3.1b2”;
myRequest.ContentLength=data.Length;
var newStream=myRequest.GetRequestStream();
newStream.Write(数据,0,数据长度);
newStream.Close();
var response=myRequest.GetResponse();
var responseStream=response.GetResponseStream();
var responseReader=新的流阅读器(responseStream);
var result=responseReader.ReadToEnd();
HtmlDocument doc=新的HtmlDocument();
doc.LoadHtml(结果);
var table=doc.DocumentNode.SelectSingleNode(“//*[@id='GridView1']”);
如果(表!=null)
{
var tr=table.SelectSingleNode(“//tr[2]”);
字符串[]trData=新字符串[12];
int rowCount=0;
foreach(tr.SelectNodes(“//td”)中的HtmlNode td)
{
行计数++;
如果(行数>3&&行数<16)
{
trData[rowCount-4]=td.InnerText;
}
如果(行数>=16)
{
打破
}
}
saveDataInDatabase(trData);
返回“干杯!数据已保存。”;
}
其他的
{
var span=doc.DocumentNode.SelectSingleNode(//span[@id='lbmessage']);
字符串消息=span.InnerText;
InsertErrorLog(uId,消息);
返回“未找到数据”;
}
}
我做了一些错误的事情,这给了我这个错误。以上错误可能是由于某些服务器设置造成的,请帮助修改设置。顺便说一下,我使用IIS 7.5作为服务器,服务器操作系统是Windows server 2008 R2


等待您的评论。

我得到了这个问题的答案。这实际上是由于SQL Server端的数据类型转换不正确造成的。我错误地将ex.innerException传递到数据类型为nvarchar的字段中。这就是发生异常的原因

因此,这里的最后一点是:如果试图将某些参数从任何语言传递到SQL server,则必须确保数据类型彼此匹配或可互操作