1

我在我的网络应用程序中使用水晶报表。我的问题是当我保留 EnableDatabaseLogonPrompt="true" 和 EnableParameterPrompt="true" 并在提示框中提供信息时,我的报告工作正常。但是当我将它们保持为假并从其背后的代码中提供信息时,总是会出现“缺少参数值”或“数据库登录失败”的错误。

我的代码如下:

.aspx 文件:

       <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" 
            AutoDataBind="True" 
            GroupTreeImagesFolderUrl="" Height="1202px" 
            ReportSourceID="CrystalReportSource1" ReuseParameterValuesOnRefresh="True" 
            ToolbarImagesFolderUrl="" ToolPanelWidth="200px" Width="903px" 
            ToolPanelView="None" EnableDatabaseLogonPrompt="False" 
            EnableParameterPrompt="False" />
        <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
            <Report FileName="CrystalReport1.rpt">
            </Report>
        </CR:CrystalReportSource>

代码背后:

       ReportDocument reportDocument = new ReportDocument();           
       reportDocument.Load(Server.MapPath("~/CrystalReport1.rpt"));
       string s=@"4EVER3-PC\MSSQLSERVER2";
       reportDocument.SetDatabaseLogon("db", "pwd", s, "databasename", true);
       reportDocument.SetParameterValue("@bankACId", "0");
       reportDocument.SetParameterValue("@fromDate", "4/11/2011 17:01:57");
       reportDocument.SetParameterValue("@todate", "4/11/2014 17:01:57");

       CrystalReportViewer1.ReportSource = reportDocument;
       CrystalReportViewer1.RefreshReport();

请指出这段代码有什么问题。这让我发疯。

4

2 回答 2

1

resolved the logon failed error.

I was accessing the database from another pc and its firewall was not allowing me to connect through crystal report. so i added sql server management studio to the list of allowed programs by firewall. So now connection problem is resolved.

So crystal report without any parameter works fine. but when i pass parameters it force closes the debug server..Any idea what should be the problem.

This is the half answer of my question which may be helpful to those who are facing connection problems.

于 2013-04-12T05:30:08.913 回答
0

.aspx 文件:

  <CR:CrystalReportViewer ID="CrystalReportViewer1" runat="server" 
            AutoDataBind="True" 
            Height="1202px" 
            ReportSourceID="CrystalReportSource1" />
        <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
            <Report FileName="CrystalReport1.rpt">
            </Report>
        </CR:CrystalReportSource>

代码背后:

 protected void btnShowReport_Click(object sender, EventArgs e)
    {
       LoadReport();           
    }

    private void LoadReport()
    {
        doc = new ReportDocument();
        doc.Load(Server.MapPath("CrSalesReport.rpt"));

        doc.SetDatabaseLogon(AppConfig.ReportServerDSUserName, AppConfig.ReportServerDSPassword, AppConfig.ReportServerDomain, "TexERP", false);

   doc .SetParameterValue("@bankACId", "0");
   doc .SetParameterValue("@fromDate", "4/11/2011 17:01:57");
   doc .SetParameterValue("@todate", "4/11/2014 17:01:57");

        CrystalReportViewer1.ReportSource = doc;
    }
于 2013-04-11T11:54:46.253 回答