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

Reference for CrystalReports.Engine.ReportDocument object class

mbenigni
Explorer
0 Likes
6,239

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!

Accepted Solutions (1)

Accepted Solutions (1)

DonWilliams
Active Contributor
0 Likes

Hi Marc,

That is odd, CR runtime will use the appropriate platform DSN.

Not sure why you are seeing it use 32 bit.... Only thing I can thing of is your app is not set to X64 in the project file.

Don

Answers (6)

Answers (6)

mbenigni
Explorer
0 Likes

Perhaps this has been the issue all along. I targeted "AnyCPU", but I'm just now noticing the "Prefer 32-bit" checkbox on the Compile tab. If this is indeed the cause of the original error, than I should be able to rename by 32-bit DSN back to a distinct name (different from the 64-bit DSN) duplicate the error, then uncheck this checkbox to force full 64-bit operation, and see a successful run. (Much as I'm tempted to just leave well enough alone.) I'll try this later today and let you know what I find.

Best,
Marc

mbenigni
Explorer
0 Likes

And that appears to have done it! I renamed our 32-bit DSN to [DSNName]32, differentiating from the 64-bit [DSNName], duplicated the database logon error, then unchecked the Prefer 32-bit checkbox. Now the application is running successfully.

In summary, it looks like the critical changes were:
- Building a WPF Application (.NET framework) rather than a WPF App (Core)
- Adding the correct v13.0 references via the Assemblies tab
- Ensuring the app was targeting a 64-bit build to correspond with the report file's 62-bit DSN reference

Thanks again to both you and Dell for all your help!

Best,
Marc

DonWilliams
Active Contributor
0 Likes

Hi Mark,

I hate this format, to many threads to follow, I like what every other Forum does, just post in a sequential stream so it's easier to follow the thread and whats been done.

OK, first thing is I don't suggest using the WPF viewer, it hasn't been developed as much as the Windows Form, and getting things fixed is tougher, it's not as robust as the Windows Form.

Open Connection is database client not being in the correct format, 32 or 64 bit, or if it's based on a PC type it tougher to find a 64 bit Client.

Uninstalling the 64 bit runtime doesn't patter at this point, it's the same one the EXE installs.

Single step through your app when you get to the database logon info and mouse over each collection and see what's missing in the collections/property bags.

Don

mbenigni
Explorer
0 Likes

Hi Don,

I couldn't agree more about the non-sequential format of this page. For a couple of days I was convinced my comments were being deleted. 😮

I'm a little bit confused about your distinction between the WPF Viewer vs. Windows Form. My application is a VB.NET WPF Application, but I haven't explicitly added a form or a Viewer object; there is no report viewer or GUI at all. All of my code (and there isn't very much of it) runs at Application Startup and then the app closes.

I think your comment concerning bitness of the database client (data source is IBM DB2 via iAccess) may be relevant. We have both 32- and 64-bit versions of this driver installed. I assumed a 64-bit application would make use of the correct 64-bit driver, but perhaps this is not happening?

I can step through the code to a breakpoint and identify the line that throws the exception, but I'm not sure how to mouse over the collections relating to the database logon info to find missing properties. I'll keep working on this. Please let me know if you have any other thoughts in the meantime, and thanks again.

Best,
Marc

P.S. I made some progress this morning. I experimented with replacing ExportToDisk with Export, to no avail. Then I tried a different report with a different (MS SQL) data source, and that worked. Since I've had success with the IBM driver in the past, I have to assume the application is making the wrong connection (32-bit vs. 64-bit) via ODBC. Continuing to experiment.

mbenigni
Explorer
0 Likes

Hello again. Based on your last response, and the progress I made this morning, I'm inclined to guess that my ODBC driver is the issue. As I said, we have both the 32-bit and 64-bit System DSN's established - but CR2020 Designer only exposes the 64-bit DSN. Is a 32-bit DSN required in order for a .NET 4.7.2 application to function properly with a CR2020 report? If anything, I would have expected 64-bit to be required.

Best,
Marc

DonWilliams
Active Contributor
0 Likes

Hi Marc,

CR 2020 is a 64 bit application so it needs the 64 DSN,

In your application you also need to set the Project platform to x64 and x86 or AnyCPU.

When you do that the references should show being loaded from the CR x64 location.

Ans since you are not using the CR's WPF viewer that part doesn't matter now.

OK so you can't simply change the reports data source from MS SQL to DB2

You need to make the change in CR Designer itself and then save one for DB2 and one for MS SQL Server and use each report based on the data source. You can use ReplaceConnection() API to up the report in code if you want though but for now use different reports to simplify.

FYI - creating 32 and 64 bit DSN's using the same name allows the app to run in 32 bit mode, CR will find which ever one it needs.

Have a look at my upgrade Blog, it describes the differences.

So your next step is to figure out why the app is not finding the correct DSN.

My Parameter test app on the WIKI page should work for you, see if that works...

Don

mbenigni
Explorer
0 Likes

Hi Don,

Yes, of course - I'd created two different reports, one for SQL and one for DB2, and changed the filenames and login information accordingly.

"FYI - creating 32 and 64 bit DSN's using the same name allows the app to run in 32 bit mode, CR will find which ever one it needs."

This is very interesting. I would have expected this to result in error, but I was able to change my 32-bit DSN name to match the 64-bit DSN name. At this point, the application ran successfully! This seems to imply that the application wants to reference the 32-bit DSN, which is counter-intuitive. I would have expected a CR2020 report to require the 64-bit DSN and driver. Does this make any sense to you?

I'll test further and work on completing this application. Thanks for the advice re: DSN names!


Best,
Marc

DonWilliams
Active Contributor
0 Likes

Hi Marc,

You don't need to manually install the MSI packages on your DEV PC.

When you install CR for Visual Studio SP33 64b installer (VS 2022 and above) it will install the 64 bit MSI but not show it in Programs and Features. At the end of the install it will prompt if you want the 32 bit runtime, Click OK and install it.

You should only see this for CR for VS, CR Designer doesn't matter for this install:

SAP Crystal Reports Runtime Engine for .NET Framework (32-bit)
SAP Crystal Reports, version for Microsoft Visual Studio (64-bit)

We don't support any higher framework than 4.8 is likely the cause, select 4.7 or 4.8 only.

Almost there...

Uninstall the 64 bit MSI and then repair the installer, because it's going to remove all of the runtime.

Thanks again

Don

mbenigni
Explorer
0 Likes

Thanks, Don. Before I uninstall/reinstall anything, did you happen to see my reply to Dell's most recent comment above? I was finally able to build a WPF App (not WPF Application) project using .NET 4.7.2, and this exposes all of the correct COM references via the Assemblies tab in the Reference Manager. The only outstanding issue is that my report object's ExportToDisk method is throwing a "Failed to open connection" exception. Do you think that uninstalling the 64-bit CR for VS and reinstalling is likely to correct this?

Thanks again,
Marc

DonWilliams
Active Contributor
0 Likes

Hi Marc,

See my Blog for upgrading, it answers a lot of your questions:

https://blogs.sap.com/2020/10/30/upgrading-a-visual-studio-2008-2019-.net-project-with-the-latest-cr...

As Dell noted, don't mix CR runtime. Version 13 is standalone and version 14 if connecting to BOE/CR Server. No longer can connect to those using CR 13 runtime, not needed if you don't.

Main thing to note is you must set all Copy Local to False, clean out your \bin folder of any CR dll's that may have been left over, mixing runtime will cause problems.

Also note with VS 2022 your app.config file should no longer be adding CR references and CR runtime is for you platform and not the OS.

Also, when adding the CR Viewer to your Windows Form be sure you are selecting the right version, I also recommend not browsing to the assemblies but using the Extensions tree in VS to select them

Don

mbenigni
Explorer
0 Likes

Thanks so much for all of this information, Don! There's a lot to process here, but I'll do some homework and report back.

Best,
Marc

mbenigni
Explorer
0 Likes

Hello again,

I've followed through your blog article, and a number of other articles linked from there. I did make some progress: it looks like I hadn't properly installed SAP Crystal Reports for Visual Studio after all. After remedying that problem, I now have the following in Programs and Features:

SAP Crystal Reports 2020 SP3 Patch 1
SAP Crystal Reports Runtime Engine for .NET Framework (32-bit)
SAP Crystal Reports Runtime Engine for .NET Framework (64-bit)
SAP Crystal Reports, version for Microsoft Visual Studio (64-bit)

All older versions (Crystal Reports 9, Crystal Reports 2008) have been uninstalled.

However, I'm still not seeing an available COM reference with which to replace/upgrade CrystalDecisions.CrystalReports.Engine, so I'm effectively stuck.

Note I'm trying to build to .NET 6.0 in VS2022 in order to best future-proof this work. Is this platform not supported?

Best,
Marc

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

DonWilliams
Active Contributor
0 Likes

Crystal Reports installer no longer includes the .NET runtime.

You need to get it from here:

https://wiki.scn.sap.com/wiki/display/BOBJ/Crystal+Reports%2C+Developer+for+Visual+Studio+Downloads

Download the CR for VS 2022 or above EXE, it will prompt at the end to install the 32 bit runtime, click OK.

Note you must install using Run as Administrator by right clicking on the EXE.

Don

mbenigni
Explorer
0 Likes

Thank you for your reply, Don!

I've already installed CR for VS2022. I believe I would have selected a 64-bit runtime however (if there was an option), since I'm running CR2020 and not CR2016.

Is there some way to confirm that this is configured properly? And should I be looking for specific reference(s) to add in my VS project? Note that the project does currently build with the CrystalReportsSourceLib Imports statement.

If it would help, I could also post my VB.NET source code. A very simple example would illustrate the functionality I'm trying to duplicate from our old CR2008 application.

Best,
Marc