Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Problem with CR 2008 and .Net 3.5 Post Reply Post New Topic
Author Message
dimsrobert
Newbie
Newbie


Joined: 06 Oct 2008
Location: United States
Online Status: Offline
Posts: 9
Quote dimsrobert Replybullet Topic: Problem with CR 2008 and .Net 3.5
    Posted: 21 Apr 2009 at 10:07am
I don't know if this is the correct place to post this but I am having a problem with my developers. I write Custom CR reports (now using CR 2008) off of a SQL Server 2008 db using tables and views.


They are developing a new application in .Net 3.5 c# and can't seem to get the reports created in CR 2008 to call using the report viewer.

Their only answer seems to be to create the reports in VS 2008 creating the data set for the report in c#.

We did this just fine using CR 11 and VB 6 but for some reason they can't seem to get it to work in .Net 3.5

We want to write the reports in CR 2008 as stand alone RPT files getting the data from the database and call them from the new application.

What are they missing?


Thanks a lot.
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 22 Apr 2009 at 12:47pm
What happens when the try to run the report?
 
Here are the basic steps they need to follow:
 
1.  Load the report into a ReportDocument object.
2.  Set the login for each table in the main report and each table any subreports.
3.  If necessary, set any parameter values that may come from your application.
4.  Set the .ReportSource of the viewer to the ReportDocument object.
 
If you need it, I have a code sample for how to set the table logins.
 
-Dell
IP IP Logged
dimsrobert
Newbie
Newbie


Joined: 06 Oct 2008
Location: United States
Online Status: Offline
Posts: 9
Quote dimsrobert Replybullet Posted: 22 Apr 2009 at 4:23pm
They get various errors at different stages.

Are you saying these steps will allow you to call a CR 2008 RPT file (not CR Basic from VS 2008) from a C3 application on a .Net 3.5 framework using the CRviewer?

We are currently working with SAP but seem to be struggling.
'
If you have any code samples they would be greatly appreciated.
'
Thanks a lot!
IP IP Logged
hilfy
Admin Group
Admin Group
Avatar

Joined: 20 Nov 2006
Online Status: Offline
Posts: 3702
Quote hilfy Replybullet Posted: 23 Apr 2009 at 7:20am
Here's the code that we use to set the table login:
If it's not already there, add
using CrystalDecisions.CrystalReports.Engine
In the constructor, do the following:
ReportDocument crReport = new ReportDocument();
crReport.Load(<filename>);
ConnectionInfo connectionInfo = new ConnectionInfo();
connectionInfo.ServerName = <server>;
connectionInfo.DatabaseName = <db name>;
connectionInfo.UserID = <userID>;
connectionInfo.Password = <password>;
// set data connections for main report
SetDBLogonForReport(connectionInfo, crReport);
// set report connection for any subreports
SetDBLogonForSubreports(connectionInfo, crReport);
// view report
crystalReportViewer.ReportSource = crReport;
-------------
private void SetDBLogonForReport(
    CrystalDecisions.Shared.ConnectionInfo connectionInfo,
    ReportDocument reportDocument)
{  
  Tables tables = reportDocument.Database.Tables;
      foreach (Table table in tables)
      {
          TableLogOnInfo tableLogonInfo = table.LogOnInfo;
          tableLogonInfo.ConnectionInfo = connectionInfo;
          table.ApplyLogOnInfo(tableLogonInfo);
      }
}
-----------
private void SetDBLogonForSubreport(
    CrystalDecisions.Shared.ConnectionInfo connectionInfo,
    ReportDocument reportDocument)
{
  Sections sections = reportDocument.ReportDefinition.Sections;
  foreach (Section section in sections)
  {
    ReportObjects reportObjects = section.ReportObjects;
    foreach (ReportObject reportObject in reportObjects)
    {
      if (reportObject.Kind == ReportObjectKind.SubreportObject)
      {
        SubreportObject subreportObject = (SubreportObject)reportObject;
        ReportDocument subReportDocument =
           subreportObject.OpenSubreport(subreportObject.SubreportName);
        SetDBLogonForReport(connectionInfo, subReportDocument);
      }
    }
  }
}
 
If you need to set the parameters for a report, you can do it at any time after the report is loaded into the Report Document and before the ReportSource of the viewer is set.
 
-Dell
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.012 seconds.