开发者

How to Export a PDF using .NET and Oracle and Dynamic Parameters

I am having difficulties getting the following to export. I am running CR2008SP2 and ASP.NET 3.5 against an Oracle 10g database.

If i do not set any of the parameters, then the page works great, and pumps out a pdf(well, except for the fact that because the parameters weren't specified, its not really the data i want. but theres no errors). If i do set the parameters, then i get the following error--

Logon failed.
Details:  [Database Vendor Code: 1005 ]Logon failed.
Details:  [Database Vendor Code: 1005 ]Error in File file {AA9A7083-D19D-454F-8454-B6CA36756895}.rpt:
Unable to connect: incorrect log on parameters.
Details:  [Database Vendor Code: 1005 ]


[COMException (0x8004100f): Logon failed.
Details:  [Database Vendor Code: 1005 ]
Logon failed.
Details:  [Database Vendor Code: 1005 ]
Error in File file {AA9A7083-D19D-454F-8454-B6CA36756895}.rpt:
Unable to connect: incorrect log on parameters.
Details:  [Database Vendor Code: 1005 ]]
   CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext) +0
   CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) +531

[LogOnException: Logon failed.
Details:  [Database Vendor Code: 1005 ]
Logon failed.
Details:  [Database Vendor Code: 1005 ]
Error in File file {AA9A7083-D19D-454F-8454-B6CA36756895}.rpt:
Unable to connect: incorrect log on parameters.
Details:  [Database Vendor Code: 1005 ]]
   CrystalDecisions.ReportAppServer.ConvertDotNetToErom.ThrowDotNetException(Exception e) +1177
   CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) +633
   CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportToStream(ExportRequestContext reqContext) +1178
   CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToStream(ExportOptions options) +154
   CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToHttpResponse(ExportOptions options, HttpResponse response, Boolean asAttachment, String attachmentName) +218
   CrystalDecisions.CrystalReports.Engine.ReportDocument.ExportToHttpResponse(ExportFormatType formatType, HttpResponse response, Boolean asAttachment, String attachmentName) +247
   AMR.RptParameter4.LoadReport(ReportState rptState) in c:\Documents and Settings\pp47067\My Documents\AMR 2\Development\AMR_TESTING_01\AMR\RptParameter4.aspx.cs:99
   AMR.RptParameter4.btnyclick(Object sender, EventArgs e) in c:\Documents and Settings\pp47067\My Documents\AMR 2\Development\AMR_TESTING_01\AMR\RptParameter4.aspx.cs:168
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

here is the code i used

public void LoadReport()
{
                    crReportDocument = new ReportDocument();


                    connectionInfo = new ConnectionInfo();
                    ParameterField paramField1 = new ParameterField();
                    ParameterField paramField2 = new ParameterField();
                    ParameterField paramField3 = new ParameterField();
                    ParameterField paramField4 = new ParameterField();
                    ParameterFields paramFields = new ParameterFields();
                    ParameterDiscreteValue paramDiscreteValue1 = new ParameterDiscreteValue();
                    ParameterDiscreteValue paramDiscreteValue2 = new ParameterDiscreteValue();
                    ParameterDiscreteValue paramDiscreteValue3 = new ParameterDiscreteValue();
                    ParameterDiscreteValue paramDiscreteValue4 = new ParameterDiscreteValue();
                    //p1
                    paramField1.Name = "Siebel Position";
                    paramDiscreteValue1.Value = txtAvailPos.Text;
                    paramField1.CurrentValues.Add(paramDiscreteValue1);
                    paramFields.Add(paramField1);

                    //p2
                    paramField2.Name = "DETAIL_LEVEL";
                    paramDiscreteValue2.Value = ddlDetailLvl.SelectedValue;
                    paramField2.CurrentValues.Add(paramDiscreteValue2);
                    paramFields.Add(paramField2);

                    //p3
                    paramField3.Name = "RPT_MONTH";
                    paramDiscreteValue3.Value = ddlMonth.SelectedValue;
                    paramField3.CurrentValues.Add(paramDiscreteValue3);
                    paramFields.Add(paramField3);
                    //p4
                    paramField4.Name = "RPT_YEAR";
                    paramDiscreteValue4.Value = txtYear.Text;
                    paramField4.CurrentValues.Add(paramDiscreteValue4);
                    paramFields.Add(paramField4);

    //setting these parameters is what will cause login issues
    //crReportDocument.SetParameterValue("Siebel Position", txtAvailPos.Text);
                    //crReportDocument.SetParameterValue("DETAIL_LEVEL", ddlDetailLvl.SelectedValue);
                    //crReportDocument.SetParameterValue("RPT_MONTH", ddlMonth.SelectedValue);
                    //crReportDocument.SetParameterValue("RPT_YEAR", txtYear.Text);


    crReportDocument.Load(Server.MapPath("~/file.rpt"));

    connectionInfo.DatabaseName="tnsnames_entry";
    connectionInfo.UserID="username";
    connectionInfo.Password="password";
    SetPermissions(connectionInfo);
    crReportDocument.ExportToHttpResponse(ExportFormatType.PortableDocFormat,
                        Response, false, "test01");
    crReportDocument.Close();
                    crReportDocument.Dispose();
                    crReportDocument = null;
    }

    private void SetPermissions(ConnectionInfo conInfo)
            {
                Sections crSections = crReportDocument.ReportDefinition.Sections;
                foreach (Section crSection in crSections)
                {
                    foreach (ReportObject crReportObject in crSection.ReportObjects)
                    {
                        if (crReportObject.Kind == ReportObjectKind.SubreportObject)
                        {
                            SubreportObject crSubReportObject = (SubreportObject)crReportObject;
                            ReportDocument subreport=crSubReportObject
                                .OpenSubreport(crSubReportObject.SubreportName);
                            foreach (CrystalDecisions.CrystalReports.Engine.Table subtbl 
                           开发者_开发问答     in subreport.Database.Tables)
                            {
                                TableLogOnInfo objTableLogonInfo = subtbl.LogOnInfo;
                                objTableLogonInfo.ConnectionInfo=conInfo;
                                subtbl.ApplyLogOnInfo(objTableLogonInfo);
                                subtbl.Location=subtbl.Location.Substring
                                    (subtbl.Location.LastIndexOf(".") +1);

                            }
                        }
                    }
                }
            }


It turns out that the report we were using was an older Crystal Reports (8 i think) report that was using a .qry file. After we converted the query to a command object (in crystal) everything worked!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜