简体   繁体   English

从Crystal Reports Viewer进行打印和导出会引发错误

[英]Printing and exporting from Crystal Reports Viewer throws error

I'm using the .net Crystal Reports viewer to display a report in an asp.net Web form. 我正在使用.net Crystal Reports查看器以asp.net Web表单显示报告。 This works properly, but when I click on the print option, and then click "OK" on the options popup, I get the following error: 这可以正常工作,但是当我单击打印选项,然后在选项弹出窗口上单击“确定”时,出现以下错误:

Access is denied. 访问被拒绝。
Description: An unhandled exception occurred during the execution of the current web request. 说明:执行当前Web请求期间发生未处理的异常。 Please review the stack trace for more information about the error and where it originated in the code. 请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。

Exception Details: System.Runtime.InteropServices.COMException: Access is denied. 异常详细信息:System.Runtime.InteropServices.COMException:访问被拒绝。

And the same thing when I try to export. 当我尝试导出时,也是一样。 I'm running this on the Visual Studio development server, VS2008. 我正在Visual Studio开发服务器VS2008上运行它。 What can I do to correct this? 我该怎么做才能纠正这个问题?

EDIT: 编辑:

Here is some code. 这是一些代码。

        txtCategory: 
    <asp:TextBox ID="txtCategory" runat="server"></asp:TextBox>
    <br />
    txtFromDate:&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="txtFromDate" runat="server" TabIndex="1"></asp:TextBox>
    <br />
    txtToDate:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="txtToDate" runat="server" TabIndex="2"></asp:TextBox>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Button ID="btnShowReport" runat="server" onclick="btnShowReport_Click" 
        TabIndex="4" Text="Show Report" />
    <br />
    <br />
    <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">

    </CR:CrystalReportSource>
    <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" 
        AutoDataBind="True" DisplayGroupTree="False" EnableDatabaseLogonPrompt="False" 
        EnableParameterPrompt="False" HasRefreshButton="True" Height="50px" 
        ReportSourceID="CrystalReportSource1" Width="350px" />

And in Code-Behind: 在代码隐藏中:

protected void btnShowReport_Click(object sender, EventArgs e)
{
    ReportDocument report = new ReportDocument();
    report.Load(Server.MapPath(@"~\ReportFiles\CrystalReport.rpt"));

    report.SetParameterValue("value1", txtCategory.Text);

    ParameterRangeValue dateRange = new ParameterRangeValue();

    CrystalReportViewer1.ReportSource = report;
}



    STACKTRACE: at CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocumentClass.Open(Object& DocumentPath, Int32 Options) 
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.Open(Object& DocumentPath, Int32 Options) 
at CrystalDecisions.ReportAppServer.ReportClientDocumentWrapper.EnsureDocumentIsOpened()

I don't know the exact answer to your question but I can suggest what I would look at which I hope helps. 我不知道您的问题的确切答案,但我可以建议您看一下,希望对您有帮助。 As it's an access denied error I would look at the access rights to where this ends up: 由于这是一个访问被拒绝的错误,因此我将查看其最终访问权限:

Server.MapPath(@"~\\ReportFiles\\CrystalReport.rpt") Server.MapPath(@“〜\\ ReportFiles \\ CrystalReport.rpt”)

A Google search for CrystalDecisions.ReportAppServer access denied suggested that you can use impersonate in the web.config to access that folder with a user that has read/write access. Google对CrystalDecisions.ReportAppServer访问被拒绝的搜索建议您可以在web.config中使用模拟来以具有读/写访问权限的用户访问该文件夹。

<authentication mode="Windows" />

<identity impersonate="true" userName="domainname\\username" password="mypassword" />

Using Windows authentication would presumably ensure the impersonation is used. 使用Windows身份验证大概可以确保使用模拟。

Hope that helps. 希望能有所帮助。

Well, I've discovered 2 things: 好吧,我发现了两件事:

1) My Visual Studio started throwing errors when I opened it, forcing me to search the ends of the internet and use devenv /resetuserdata to reset the environment. 1)我打开Visual Studio时,它开始引发错误,迫使我搜索Internet的两端并使用devenv / resetuserdata重置环境。 That fixed part of it. 那是固定的部分。 I also repaired my .NET installations, but I don't know if that did anything. 我还修复了.NET安装,但是我不知道这是否起作用。

2) Apparently I needed to refresh the reportviewer after assigning the report to the viewer in my code. 2)显然,在我的代码中将报告分配给查看器之后,我需要刷新reportviewer。

I added this: 我添加了这个:

CrystalReportViewer1.RefreshReport();

To the bottom of my code, and viola! 在我的代码底部,中提琴! Now I can export and print. 现在,我可以导出和打印了。 How simple and nuts is that? 那有多么简单和疯狂?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM