cancel
Showing results for 
Search instead for 
Did you mean: 

Fail to display crystal report in dot net application

Former Member
0 Kudos

I created my reports using CR Developer V 14.1.5.1501 and tried to display them in my dot net application using Crystal Report Viewer 2013.

If I assigned the CrystalReportViewer object a report at the design time then the report can be displayed(either reports with built in sub reports or report with import sub reports will be displayed fine)

If I used the ReportDocument object to load the report on the fly, I will get the "Failed to open connection error..." for reports with import sub reports. The other type is working just fine.(I did loop thru all the sub reports to assign the log on information and did so with the main report). I need to use the ReportDocument object so that I can export the report to PDF form and all my reports have import sub reports. Please help!!!

Accepted Solutions (0)

Answers (7)

Answers (7)

0 Kudos

Why are you commenting out the Server and DB names?

Also, since you are using .NET you should use this tag:

SAP Crystal Reports, version for Visual Studio

Former Member
0 Kudos

ReportDocument cryRpt = new ReportDocument();

TableLogOnInfos crtableLogoninfos = new TableLogOnInfos();
TableLogOnInfo crtableLogoninfo = new TableLogOnInfo();
ConnectionInfo crConnectionInfo = new ConnectionInfo();
Tables CrTables;

//cryRpt.Load("c:\\Test\\Report2.rpt");
//cryRpt.Load("c:\\Test\\DailyLogtest.rpt");
//cryRpt.Load("c:\\Test\\report-byron.rpt");
//cryRpt.Load("c:\\Test\\StatementSummary.rpt");
cryRpt.Load("c:\\Test\\nsurgtemplatemaps.rpt");



CrystalDecisions.CrystalReports.Engine.ReportObjects crReportObjects;
CrystalDecisions.CrystalReports.Engine.SubreportObject crSubreportObject;
CrystalDecisions.CrystalReports.Engine.ReportDocument crSubreportDocument;
CrystalDecisions.CrystalReports.Engine.Database crDatabase;
CrystalDecisions.CrystalReports.Engine.Tables crTables;
TableLogOnInfo crTableLogOnInfo;

//set the crSections object to the current report's sections
CrystalDecisions.CrystalReports.Engine.Sections crSections = cryRpt.ReportDefinition.Sections;

//loop through all the sections to find all the report objects
foreach (CrystalDecisions.CrystalReports.Engine.Section crSection in crSections)
{
crReportObjects = crSection.ReportObjects;
//loop through all the report objects to find all the subreports
foreach (CrystalDecisions.CrystalReports.Engine.ReportObject crReportObject in crReportObjects)
{

if (crReportObject.Kind == ReportObjectKind.SubreportObject)
{
//MessageBox.Show(crReportObject.Name);
//you will need to typecast the reportobject to a subreport
//object once you find it
crSubreportObject = (CrystalDecisions.CrystalReports.Engine.SubreportObject)crReportObject;

//open the subreport object
crSubreportDocument = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName);

//set the database and tables objects to work with the subreport
crDatabase = crSubreportDocument.Database;
crTables = crDatabase.Tables;

//loop through all the tables in the subreport and
//set up the connection info and apply it to the tables
foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
{
//crConnectionInfo.ServerName = "serveraddress";
//crConnectionInfo.DatabaseName = "DB";
crConnectionInfo.UserID = "Master";
crConnectionInfo.Password = "Test";


crTableLogOnInfo = crTable.LogOnInfo;
crTableLogOnInfo.ConnectionInfo = crConnectionInfo;
crTable.ApplyLogOnInfo(crTableLogOnInfo);
}
}
}
}


//crConnectionInfo.ServerName = "serveraddress";
//crConnectionInfo.DatabaseName = "DB";
crConnectionInfo.UserID = "Master";
crConnectionInfo.Password = "Test";

CrTables = cryRpt.Database.Tables;
foreach (CrystalDecisions.CrystalReports.Engine.Table CrTable in CrTables)
{
crtableLogoninfo = CrTable.LogOnInfo;
crtableLogoninfo.ConnectionInfo = crConnectionInfo;
CrTable.ApplyLogOnInfo(crtableLogoninfo);
}


crystalReportViewer1.ReportSource = cryRpt;
crystalReportViewer1.Refresh();

0 Kudos

Still need details about your code....

Former Member
0 Kudos

I set up the system dsn when designed the reports and I tried to use that connection as well in the application. Thanks

0 Kudos

Hi Phu,

Search for my Parameter test app, it has log on abilities with connections to subreports as well and see if that works for you.

Need details about your Data source and how you are connecting as well.

Except there is an issue with Blogs right now so I can't find it.

Don

Former Member
0 Kudos

I use the SDK service pack 17. Thanks

0 Kudos

What SDK package are you using in your application?