簡體   English   中英

Infopath FileQueryConnection.Execute(XpathNavigator)引發System.Net.WebException:嘗試讀取或寫入受保護的內存

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

我在啟用瀏覽器的infopath表單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)

為什么會引發這樣的異常? 我在代碼中缺少什么嗎?

謝謝您的幫助!

它最有可能是由FileQueryConnection引起的。 由於從未使用con變量,因此請刪除以下行:

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

con.Execute(outputRootNavigator); 寫入日志文件之前,應在此處關閉連接“ con”。 File.AppendAllText(@“ E:\\ log.txt”,outputRootNavigator.ToString());

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM