Infopath FileQueryConnection.Execute(XpathNavigator) throws

本文关键字:throws XpathNavigator FileQueryConnection Execute Infopath | 更新日期: 2023-09-27 17:50:27

我在浏览器启用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());
        }

我得到这个异常-

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)

为什么会抛出这样的异常?我在我的代码错过了什么?

谢谢你的帮助!

Infopath FileQueryConnection.Execute(XpathNavigator) throws

con.Execute(outputRootNavigator);你应该在写日志文件之前关闭这里的连接"con"。File.AppendAllText(@"E: ' log.txt outputRootNavigator.ToString ());

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

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