Quantcast
Channel: SCN : Discussion List - SAP Crystal Reports, version for Visual Studio
Viewing all articles
Browse latest Browse all 3636

Issue dynamically setting a report datasource at runtime

$
0
0

I'm hoping that someone can offer me some help with an issue I am facing.  I have recently upgraded my .NET solution from Crystal Reports XI R2 in Visual Stuido 2008 to Crystal Reports for Visual Studio 2010 (SP5) in Visual Studio 2010.  Prior to the upgrade, the scenario which I describe below was working.  After the upgrade, I cannot seem to get my reports to work. 

 

What I am trying to accomplish is as follows:

  • Developers create Crystal Reports within their own development environments
  • The developers then drop their Crystal Reports onto the server at a predefined location
  • My code dynamically loads the Crystal Report file, which includes dynamically setting the datasource to a dataset (that the application populates)
  • My code then exports the report as a pdf to the http stream

 

I have stepped through my code, and the point at which an exception occurs is when I invoke the ExportToHttpResponse method of the report.  The exception I receive is:

 

[COMException (0x8004100f): Database logon failed.]

   CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext) +0

   CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) +362

 

So I'm hoping someone can answer some questions I have about this and offer a solution to fixing my issue:

 

  1. If I am setting the datasource dynamically in my code to a dataset that my application fills (using it's database connectivity), why is the report trying any login to the database at all?  Should it not simply apply the dataset I have provided it?
  2. It appears that I am required to create a system ODBC entry that matches the connection name used when creating the report, otherwise I receive the following exception:

 

[COMException (0x800002f4): Failed to open the connection.

Failed to open the connection.

Variance_Report_01 {79B1EDF1-50B7-472F-B1F4-FEDFE5337CD1}.rpt]

   CrystalDecisions.ReportAppServer.Controllers.ReportSourceClass.Export(ExportOptions pExportOptions, RequestContext pRequestContext) +0

   CrystalDecisions.ReportSource.EromReportSourceBase.ExportToStream(ExportRequestContext reqContext) +362

 

Again, why is the report trying to open a connection on it's own when I have specified the datasource dynamically in my code to a dataset?

 

I have reviewed numerous other posts within this site (and many others) and have tried all of the suggested solutions (re-installing the runtime, setting permissions on the temp folder to the application pool identity, ensuring I have properly closed and disposed of the report object in the code, etc...) but nothing has fixed the issue.


This report does not work on any of my environments, including my local development machine.  Here is an excerpt of the .NET code I am using to do this:

 

ReportDocument oRpt = null;

//create a Crystal Report document object, and load in the passed in report

oRpt = newReportDocument();

oRpt.Load(Server.MapPath(sReportName));

 

//Set the Data Source for the project to the passed in query

DataSet dsReportSource = newDataSet();

dsReportSource = ExecuteCrystalQuery(sDynamicSQL);

oRpt.SetDataSource(dsReportSource);

oRpt.Database.Tables[0].SetDataSource(dsReportSource);

 

//Export report to PDF

oRpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, false, "");

 

oRpt.Close();

oRpt.Dispose();

GC.Collect();

 

Can someone please offer some advice or suggest a fix that I haven't previously tried?

 

Thanks


Viewing all articles
Browse latest Browse all 3636

Trending Articles