Skip to Content
0

Fail to display crystal report in dot net application

Oct 12, 2016 at 08:19 PM

43

avatar image

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!!!

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

7 Answers

Don Williams
Oct 12, 2016 at 08:20 PM
0

What SDK package are you using in your application?

Share
10 |10000 characters needed characters left characters exceeded
PHU PHAN Oct 13, 2016 at 02:16 PM
0

I use the SDK service pack 17. Thanks

Share
10 |10000 characters needed characters left characters exceeded
Don Williams
Oct 13, 2016 at 02:27 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
PHU PHAN Oct 13, 2016 at 04:50 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Don Williams
Oct 13, 2016 at 04:55 PM
0

Still need details about your code....

Share
10 |10000 characters needed characters left characters exceeded
PHU PHAN Oct 13, 2016 at 09:25 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded
Don Williams
Oct 13, 2016 at 09:28 PM
0

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

Share
10 |10000 characters needed characters left characters exceeded