Infopath FileQueryConnection.Execute(XpathNavigator)抛出System.Net.WebException:尝试读取或写入受保护的内存

时间:2011-04-19 06:11:26

标签: c# asp.net xml sharepoint infopath

我在2007年浏览器启用的infopath表单的字段更改事件中包含此代码 -

 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());
        }

我得到了这个例外 -

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)

为什么会抛出这样的异常?我在代码中遗漏了什么吗?

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

最有可能是由FileQueryConnection引起的。由于从不使用con变量,请删除以下行:

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

答案 1 :(得分:0)

con.Execute(outputRootNavigator); 在写入日志文件之前,您应该在此处关闭连接“con”。 File.AppendAllText(@“E:\ log.txt”,outputRootNavigator.ToString());