cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Reference for CrystalReports.Engine.ReportDocument object class

mbenigni
Explorer
0 Likes
6,243

Hello, all.

I'm trying to build a simple VS2022 test application integrating the trial version of CR2020. There is effectively one line of code:

Dim CrystalReportSource1 As New CrystalDecisions.CrystalReports.Engine.ReportDocument

Which is returning an error:

BC30002 Type 'CrystalDecisions.CrystalReports.Engine.ReportDocument' is not defined.

I need to know what reference to add or Import in order to be able to use this ReportDocument object class (or an alternate object class name, if this has changed to something outside the CrystalDecisions namespace.) I've tried a number of Crystal Reports 14.0 references that looked promising but didn't help. And in previous (CR2008) versions of this same project I had successfully used the following Imports statements, but the targets are no longer found:

Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.CrystalReports.Engine.ReportDocument

Thanks in advance!

View Entire Topic
DellSC
Active Contributor
0 Likes

With Crystal for VS, you need to reference the version 13.x.x.x assemblies in your application, not the version 14.x.x.x assemblies.

-Dell

mbenigni
Explorer
0 Likes

Thank you, Dell - this is really valuable information! Can you tell me which references (and corresponding Imports statements) I should be using, or direct me to documentation?

The (formerly working) CR2008 code I'm trying to replicate simply opens source files and exports in various formats. Here's a simplified version:

Imports CrystalDecisions.Shared
Imports CrystalDecisions.CrystalReports.Engine
Imports CrystalDecisions.ReportSource
Imports CrystalDecisions.Windows.Forms

Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim CrystalReportSource1 As New CrystalDecisions.CrystalReports.Engine.ReportDocument

CrystalReportSource1.FileName = "\\Server\Templates\test.rpt"
CrystalReportSource1.SetDatabaseLogon("UserName", Environment.GetCommandLineArgs(1))
CrystalReportSource1.ExportToDisk(ExportFormatType.CrystalReport, "\\Server\Results\test.rpt")
CrystalReportSource1.Close()
CrystalReportSource1 = Nothing
End Sub

End Class

DellSC
Active Contributor
0 Likes

Those references are correct.

Looking at your code, instead of setting .FileName, you may want to try CrystalReportSource1.Load("\\Server\Templates\test.rpt").

Definitely look at the conversion information at the URL that Don posted below.

-Dell

mbenigni
Explorer
0 Likes

Thank you, Dell!

When you say "those references are correct", are you referring to the four Imports statements at the top of my code? On build, VS reports that these namespaces cannot be found. As a result, there is an error as soon as I try to create the new CrystalDecisions.CrystalReports.Engine.ReportDocument object. I think the fundamental problem is that I'm not finding the CrystalDecisions.CrystalReports.Engine reference when I try to add a v13.0 COM reference to the project. Is there something about this combination of products (CR2020, VS2022, .NET 6.0) that is not supported?

Best,
Marc

DellSC
Active Contributor
0 Likes

You cannot add the COM components directly! They're no longer licensed for direct access from your code. Instead,

1. Right-click on "References" in the Solution Explorer pane and select "Add Reference" to bring up the Reference Manager.

2. Click on "Extensions" on the left. It may take a bit, but you will then see the Crystal Decisions assemblies.

3. Select the 4 assemblies that you have in your Using clause. It will look something like this:

4. Click on "OK".

5. For each of the CrystalDecisions assemblies that you've added, select it under "References" and look at its properties. Make sure that the "Embed Interop Types" property is set to False.

-Dell

mbenigni
Explorer
0 Likes

Thanks again, Dell! I've made some progress; I think I'm close to having this completed.

I had been struggling because the contents of References Manager looked very different than yours and Don's. It turned out I'd built my project from the WPF Application template rather than the WPF App template. After creating a new project with the latter, VS presents an Assemblies group in Reference Manager. From there, all of the references were available (and Embed Interop Types was False for each by default.)

At this point my code will build without errors or warnings, and it will run all the way through the ExportToDisk method call. (Both my original FileName property setting or your recommended Load method replacement appear to run fine.) However, the app throws an exception on ExportToDisk, indicating:

CrystalDecisions.CrystalReports.Engine.InternalException: 'Failed to open the connection.'

This is strange since SetDatabaseLogon is successful, and any other connection information is embedded in the report. Can you shed any light on this? Are there other required steps that have been added as of CR2020?

Best,
Marc

DellSC
Active Contributor
0 Likes

Do you have any subreports? If so, are you explicitly using SetDatabaseLogon for each of them? If not, that could cause this problem.

Also, I think I recall hearing about an error at one point in time with either ExportToDisk or ExportToStream - the resolution was to use the the other one of these two methods instead. I don't remember which was the correct one, though.

-Dell

mbenigni
Explorer
0 Likes

Thanks for getting back, Dell.

No, there are no subreports - this is a very simple report with just one connection and one data table.

I tried replacing ExportToDisk with ExportToStream, but the latter method doesn't take any parameters relating to destination, filename, etc. Apparently all of this needs to be set up via other properties/ methods in advance, but I can't find any documentation or sample code to illustrate. For the moment ExportToDisk seems closer to working. If you can recommend or link to any documentation concerning ExportToStream I would be grateful.

Best,
Marc