Link to home
Start Free TrialLog in
Avatar of sthamilton
sthamilton

asked on

Populate Report with Data Reader

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();
Avatar of Mike McCracken
Mike McCracken

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
Avatar of sthamilton

ASKER

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!
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
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial