Click here to Skip to main content
15,113,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am using crystal report in my application. I am binding the values and I am showing the grid to the user its working fine. When I like to save the crystal report into the folder with converting it into pdf format it showing the error as "DATABASE Logon failed" but the report is showing correctly but it is not saving into the folder. I given the
oRpt.SetDatabaseLogon
then also it giving the same error. Can anyone help me to solve this problem. Here is the code:

  ReportDocument oRpt = new ReportDocument();
    ExportOptions rptSave=new ExportOptions();
    DiskFileDestinationOptions rptSave1=new DiskFileDestinationOptions();
DataSet dsQuote= objQI.FillDataforPrint();
                if (rdbTaxSelection.SelectedValue == "Y")
                {
                    CrystalReportSource1.Report.FileName = Server.MapPath("~/newquote.rpt");

                    string reportpath = Server.MapPath("~/newquote.rpt");
                    oRpt.Load(reportpath);
                }
                else if (rdbTaxSelection.SelectedValue == "N")
                {
                    CrystalReportSource1.Report.FileName = Server.MapPath("~/quote.rpt");

                    string reportpath = Server.MapPath("~/quote.rpt");
                    oRpt.Load(reportpath);

                }
                 CrystalReportSource1.ReportDocument.Database.Tables["Request"].SetDataSource(dsQuote.Tables[0]);
                 CrystalReportSource1.ReportDocument.Database.Tables["Items"].SetDataSource(dsQuote.Tables[1]);
                 CrystalReportSource1.ReportDocument.Database.Tables["TC"].SetDataSource(dsQuote.Tables[2]);
                 CrystalReportSource1.ReportDocument.Database.Tables["BO"].SetDataSource(dsQuote.Tables[3]);
               
                 oRpt.SetDatabaseLogon("username", "password","servername","Databasename");
                 oRpt.SetDataSource(dsQuote.Tables[0]);
                 oRpt.SetDataSource(dsQuote.Tables[1]);
                 oRpt.SetDataSource(dsQuote.Tables[2]);
                 oRpt.SetDataSource(dsQuote.Tables[3]);



                if (dsQuote.Tables[1].Rows.Count > 0)
                {                                        
                    CrystalReportViewer1.Visible = true;
                    CrystalReportViewer1.ReportSource = CrystalReportSource1;              
                    CrystalReportViewer1.DataBind();            
                                 
                    CrystalReportViewer1.Visible = true;

                }
            }
                MemoryStream MemStream = new MemoryStream();
                MemStream = (MemoryStream)CrystalReportSource1.ReportDocument.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
                Response.Clear();
                Response.Buffer = true;
                Response.ContentType = "application/PDF";
                Response.BinaryWrite(MemStream.ToArray());

               
                string fileName = "Q" + SessionVarriables.BidIdSession + ViewState["Slno"].ToString().PadLeft(2, '0');               
                string filePath = Server.MapPath("~/AttachDocument/") + fileName + ".pdf";
               
                oRpt.ExportToDisk(ExportFormatType.PortableDocFormat, filePath);
                Response.End();  


Thanks in Advance
Posted

1 solution

   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900