We help IT Professionals succeed at work.

Populate Report with Data Reader

sthamilton
sthamilton asked
on
1,341 Views
Last Modified: 2011-09-20
What is the proper way to populate a crystal report using a SqlDataReader?  It seems simple enough to do so by simply using rpt.SetDataSource(rdr), but this doesn't appear to work for me.  When executing the following code on my development machine it works perfectly.  However when executing it on a production machine it gives the following error that says "login falied".  Can anyone see what I am doing wrong?


CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
                                    
rpt.Load(rptfile);

SqlConnection conReport = new SqlConnection(SOLIMPMODULES.ImportSQL.strConn);
SqlCommand cmdReport = new SqlCommand(strReportSrc, conReport);
cmdReport.CommandType = CommandType.StoredProcedure;

conReport.Open();

SqlDataReader rdr = cmdReport.ExecuteReader();

rpt.SetDataSource(rdr);

foreach(CrystalDecisions.CrystalReports.Engine.Table tbl in rpt.Database.Tables)
{
      tbl.SetDataSource(rdr);
}

rpt.Refresh();

CrystalDecisions.Shared.DiskFileDestinationOptions dopt = new CrystalDecisions.Shared.DiskFileDestinationOptions();

dopt.DiskFileName = strPDFName;

rpt.ExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile;
rpt.ExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
rpt.ExportOptions.DestinationOptions = dopt;

rpt.Export();
Comment
Watch Question

Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
What version of Crystal?  What language is the application written in?

Looks like C++ so this may be useful
http://support.businessobjects.com/communityCS/FilesAndUpdates/rdccpp85.exe.asp

Is the SQLDataReader anything like an ADO recordset?

If so this may shed some light
http://support.businessobjects.com/communityCS/FilesAndUpdates/ADO_ConnectionMethods.zip.asp

mlmcc

Author

Commented:
The code is C# using the CrystalDecisions.CrystalReports.Engine objects and the embedded version of crystal reports.  I think that I figured out that it is a bad idea to use the datareader object to bind to the report.  Since in the report designer I can't base the report off of the datareader object it seems to be unable to bind the tables.  I have managed to work around it by converting the data reader to a dataset and generating an XML file which I can then bind the report to.  Thanks for the help though!
Mike McCrackenSenior Consultant
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2013

Commented:
Glad to hear you solved it.  I don't know as much about C# as I should.  Maybe I will find time soon to expand my horizons.

mlmcc
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.