Infopath FileQueryConnection.Execute(XpathNavigator) throws System.Net.WebException: Attempted to read or write protected memory

♀尐吖头ヾ 提交于 2019-12-25 01:40:29

问题


I have this code inside a field changed event of a browser enabled infopath form 2007 -

 try
        {

        XmlDocument outputFile = new XmlDocument();
FileQueryConnection con = (FileQueryConnection)DataConnections["connection1"];
con.FileLocation = @"http://server_name/_vti_bin/owssvr.dll"
         + "?Cmd=Display&List={List_ID}"
         + "&XMLDATA=TRUE&View={View_ID}&Query=*"
            + "&FilterField1=Country_x0020_Name&FilterValue1="
            + country.Replace("&","%26");
            outputFile.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\" ?><outputRoot></outputRoot>");

            XmlNamespaceManager outputFileNamespaceManager = new XmlNamespaceManager(outputFile.NameTable);

            // XmlDocument output file created above.
            XPathNavigator outputFileNavigator = outputFile.CreateNavigator();
            XPathNavigator outputRootNavigator = 
            outputFileNavigator.SelectSingleNode("/outputRoot",outputFileNamespaceManager);
            con.Execute(outputRootNavigator);
            File.AppendAllText(@"E:\log.txt", outputRootNavigator.ToString());
        }
        catch (Exception exp)
        {
            File.AppendAllText(@"E:\exp.txt", exp.ToString());
        }

I get this exception -

System.Net.WebException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.at Microsoft.Office.InfoPath.Internal.MomExceptionHelper.ExecuteDataConnectionAction(OMCall d) at Microsoft.Office.InfoPath.Internal.FileQueryConnectionHost.Execute(XPathNavigator output) at cascadeTemplate.FormCode.field1_Changed(Object sender, XmlEventArgs e)

Why is there an exception thrown like this? Am i missing something in my code?

Thanks for the help!


回答1:


con.Execute(outputRootNavigator); You Should close the connection "con" here before writing log file. File.AppendAllText(@"E:\log.txt", outputRootNavigator.ToString());




回答2:


Its most likely caused by FileQueryConnection. Since the con variable is never used, remove the the following lines:

     FileQueryConnection con = (FileQueryConnection)DataConnections["connection1"];
     con.FileLocation = ...


来源:https://stackoverflow.com/questions/5712295/infopath-filequeryconnection-executexpathnavigator-throws-system-net-webexcept

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!