Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I had a application with Ms Acess database .In one of its form I use a Crystal report viewer to show a crystal report but the issue is that after loading its giving blank report and if I try to refresh the report its giving the error

Crystal report windowsform viewer message box

Failed to open the connection



My code is as below

C#
private void button1_Click(object sender, EventArgs e)
            {
                try
                {
                    crystalReportViewer1.ReportSource = getpeport(@"C:\shrinkage\New folder\Shrinkage details1-bysreenath.rpt");
    
    
    
                    crystalReportViewer1.SelectionFormula = "{CONS_MAST.CONSID} = '" + cmb_cons.Text + "' and {CONSUMPTION.STYLE} = '" + cmb_style.Text + "' and {CONSUMPTION.BUYER} = '" + cmb_buyer.Text + "'";
                //crystalReportViewer1.RefreshReport ();
                }
                catch (Exception exp)
                {
    
                    MessageBox.Show(exp.ToString());
                }
                finally
                {
                    oleDbConnection1.Close();
                }
              //  crystalReportViewer1.RefreshReport();
            }        
        
    
    
            public ReportDocument getpeport(String ReportLocation)
            {
                ConnectionInfo crconnectioninfo = new ConnectionInfo();
                ReportDocument cryrpt = new ReportDocument();
                TableLogOnInfos crtablelogoninfos = new TableLogOnInfos();
                TableLogOnInfo crtablelogoninfo = new TableLogOnInfo();
    
                Tables CrTables;
    
               
    
                crconnectioninfo.ServerName = @"C:\shrinkage\Shrinkage.mdb";
                crconnectioninfo.DatabaseName = "";
          crconnectioninfo.UserID = "";
         crconnectioninfo.Password = "";
    
                cryrpt.Load(ReportLocation);
    
                CrTables = cryrpt.Database.Tables;
    
                foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
                {
                    crtablelogoninfo = CrTable.LogOnInfo;
                    crtablelogoninfo.ConnectionInfo = crconnectioninfo;
                    CrTable.ApplyLogOnInfo(crtablelogoninfo);
                }
              //  cryrpt.Refresh ();
                return cryrpt;
            }



This report was designed in Crystal report XI and there I am able to do the refresh and view the data also.Pls help me with a suggestion
Posted

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