当前位置: 代码迷 >> .NET报表 >> Access to report file denied. Another program may be using it.(水晶报表导出PDF时的异常)
  详细解决方案

Access to report file denied. Another program may be using it.(水晶报表导出PDF时的异常)

热度:10174   发布时间:2013-02-25 00:00:00.0
Access to report file denied. Another program may be using it.(水晶报表导出PDF时的错误)
C# code
ReportDoc.Load(Server.MapPath("../Report") + "\\CrystalReport2.rpt");            SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=Buyautomation;User ID=sa;Password=123456");            SqlCommand comm = new SqlCommand("SELECT * FROM View_tbOperate", conn);            SqlDataAdapter adapter = new SqlDataAdapter();            if (conn.State == ConnectionState.Closed) conn.Open();            // get data from db            DataSet2 ds = new DataSet2();            adapter.SelectCommand = comm;            adapter.Fill(ds, "View_tbOperate");            conn.Close();            // set data to report            ReportDoc.SetDataSource(ds);            ReportDoc.Refresh();            // set output type "pdf"            ReportDoc.ExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;            ReportDoc.ExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;            CrystalDecisions.Shared.DiskFileDestinationOptions options = new CrystalDecisions.Shared.DiskFileDestinationOptions();            options.DiskFileName = Server.MapPath("../DOC") + "\\Chap0101.pdf";            ReportDoc.ExportOptions.DestinationOptions = options;            FileLockedThenWait(Server.MapPath("../DOC") + "\\Chap0101.pdf");            if (File.Exists(Server.MapPath("../DOC") + "\\Chap0101.pdf"))            {                File.Delete(Server.MapPath("../DOC") + "\\Chap0101.pdf");            }            ReportDoc.Export();            //set data to view            //this.CrystalReportViewer1.ReportSource = ReportDoc;  


代码是没问题的,路径也没问题,我之前用的绝对路径。
最后一行如果不注释是可以显示出来报表的。
可是为什么导出PDF的时候就出那样的错误呀。

Access denied.
Error in File C:\WINDOWS\TEMP\CrystalReport2 {224FCD06-3376-4BBB-B1A7-0CA9E6486270}.rpt:
Access to report file denied. Another program may be using it.

头大,搜索了一天也没解决,有人说是权限的问题,我已经把那个DOC文件夹加上了ASPNET所有权限,
不行,也加了一个EYERYONE所有权限,还是不行。到底啥原因呀。

救救我呀~~

------解决方案--------------------------------------------------------
重新启动机器后,不要启动水晶报表,把temp目录全部清空掉
然后再试
------解决方案--------------------------------------------------------
还有,服务器的temp目录也要给everyone 可写权限。
------解决方案--------------------------------------------------------
顶阿泰
  相关解决方案