Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi everyone,
I setup my soft in other computers, when i run crystal report have problem, i installed runtime in that computer. Please help me, thanks all
http://www.upsieutoc.com/image/zWK[^]
This is my Code
C#
public ReportDocument LoadCrystalReportViewer(CrystalReportInfo crInfo, out string message)
        {
            message = "";
            try
            {
                if (crInfo != null)
                {

                    string ReportPath = null;
                    ReportDocument rptDocument = new ReportDocument();

                    if (crInfo.IsFullPath)
                    {
                        ReportPath = crInfo.ReportName;
                    }
                    else
                    {
                        ReportPath = Application.StartupPath + "/Reports/" + crInfo.ReportName + ".rpt";
                    }

                    if (!System.IO.File.Exists(ReportPath))
                    {
                        message = "Report not found.";
                        return null;
                    }

                    rptDocument.Load(ReportPath);

                    //Set Value to Formulas if exists
                    if (crInfo.FormulaList != null)
                    {
                        foreach (var f in crInfo.FormulaList)
                        {
                            if (f.SubReportName == null || f.SubReportName.Trim() == "")
                            {
                                rptDocument.DataDefinition.FormulaFields[f.FormulaName].Text = "\"" + f.FormulaValue + "\"";
                            }
                            else
                            {
                                rptDocument.Subreports[f.SubReportName].DataDefinition.FormulaFields[f.FormulaName].Text = "\"" + f.FormulaValue + "\"";
                            }
                        }
                    }

                    if (crInfo.IsConnectDirectSQL == false)
                    {
                        ///Set Database to report
                        ///
                        if (crInfo.DataSourceList != null)
                        {
                            foreach (var o in crInfo.DataSourceList)
                            {
                                if (o.SubReportName == null || o.SubReportName.Trim() == "")
                                {
                                    rptDocument.Database.Tables[o.TableName].SetDataSource(o.DataSource);

                                    //rptDocument.SetDataSource(o.DataSource);
                                }
                                else
                                {
                                    rptDocument.Subreports[o.SubReportName].Database.Tables[o.TableName].SetDataSource(o.DataSource);
                                }
                            }
                        }
                    }
                    else
                    {
                        //Set connection info to report login to database sql, oracle, ... & set parameters
                        ConnectionInfo LogonInfo = new ConnectionInfo();

                        LogonInfo.ServerName = crInfo.ServerName;
                        LogonInfo.UserID = crInfo.UserName;
                        LogonInfo.Password = crInfo.Password;
                        LogonInfo.DatabaseName = crInfo.DatabaseName;

                        TableLogOnInfo tableLogOnInfo = new TableLogOnInfo();

                        foreach (Table table in rptDocument.Database.Tables)
                        {
                            tableLogOnInfo = table.LogOnInfo;
                            tableLogOnInfo.ConnectionInfo = LogonInfo;
                            table.ApplyLogOnInfo(tableLogOnInfo);
                        }

                        ////Apply log on Info to Subreport
                        foreach (ReportDocument srd in rptDocument.Subreports)
                        {
                            foreach (CrystalDecisions.CrystalReports.Engine.Table table in srd.Database.Tables)
                            {
                                tableLogOnInfo = table.LogOnInfo;
                                tableLogOnInfo.ConnectionInfo = LogonInfo;
                                table.ApplyLogOnInfo(tableLogOnInfo);
                            }
                        }

                        //Set Params
                        if (crInfo.ParamList != null)
                        {
                            foreach (var p in crInfo.ParamList)
                            {
                                if (p.SubReportName == null || p.SubReportName.Trim() == "")
                                {
                                    rptDocument.SetParameterValue(p.ParamName, p.ParamValue);
                                }
                                else
                                {
                                    rptDocument.SetParameterValue(p.ParamName, p.ParamValue, p.SubReportName);
                                }
                            }
                        }
                    }


                    //Show Preview
                    if (crInfo.IsPreview)
                    {
                        crystalReportViewer1.ReportSource = rptDocument;
                    }
                    else
                    {
                        //Print to Printer
                        if (!string.IsNullOrEmpty(crInfo.PrinterName))
                        {
                            rptDocument.PrintOptions.PrinterName = crInfo.PrinterName;
                        }
                        rptDocument.PrintToPrinter(1, false, 0, 0);
                    }

                    return rptDocument;
                }
                else
                {
                    message = "Please initial information before load report.";
                    return null;
                }
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return null;
            }
        }
Posted
Updated 28-May-14 0:15am
v2
Comments
KaushalJB 28-May-14 6:40am    
Where is your Database name in your Login Image..
khoi tran 28-May-14 7:39am    
in my code i setuped database already (LogonInfo.DatabaseName = crInfo.DatabaseName;), but when i run not see
KaushalJB 28-May-14 7:42am    
Display your actual error message or image ...
khoi tran 28-May-14 8:01am    
My error cant run report, and it only show form login when i open report such as image link http://www.upsieutoc.com/image/zWK
KaushalJB 28-May-14 8:11am    
According to your description please check the path that you access for reports and permissions for that path in properties because if its read only it can matter for reports, and clear your %temp%. Another thing Database for report need to be configured in Data Expert in Crystal Reports.

1 solution

C#
RptDocument.SetDatabaseLogon(crInfo.UserName, crInfo.Password, crInfo.ServerName, crInfo.DataBaseName);
 
Share this answer
 
v2

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