简体   繁体   中英

No mapping exists from object type System.Net.Sockets.SocketException to a known managed provider native type

I have created a webpage that is able to post some value to other website and get the response from that page as a HTML document. After I get the response from the other website, I am parsing it with the help of HTMLAgilityPack and getting the required data. This data is then saved in a SQL Server database. This all scenario is working fine in development environment but after deployment at the server, it is giving the above error.

Here is the function where I am getting the data from other website, parsing and saving it.

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";
        }
}

Where I am doing some wrong thing, which is giving me this error. May be the above error is due to some server settings, please help to modify the settings. By the way, I am using IIS 7.5 as the server and the server OS is Windows server 2008 R2.

waiting for your comments.

I got the answer to this problem. It was actually occurring due to improper datatype conversion at the SQL Server end. By mistake i was passing ex.innerException into a field of datatype nvarchar. This is why the exception was occurring.

Hence the final point here is: if you try to pass some parameter from any language to SQL server, you must make sure that the datatypes are matching or interoprable with each other.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM