2009-10-19 53 views
0

我難以獲取以下內容以導出。我針對Oracle 10g數據庫運行CR2008SP2和ASP.NET 3.5。如何使用.NET和Oracle導出PDF以及動態參數

如果我沒有設置任何參數,那麼這個頁面很好用,並且抽出一個pdf(好吧,除了因爲沒有指定參數,它並不是我想要的數據。 theres沒有錯誤)。如果我這樣做設置參數,然後我得到以下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 

這裏是我用

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); 

          } 
         } 
        } 
       } 
      } 

回答

0

事實證明,我們使用的報告是一箇舊的Crystal Reports的代碼( 8我認爲)報告使用.qry文件。在我們將查詢轉換爲命令對象(水晶)後,一切正常!

相關問題