ast2550,
as I said - I already downloaded that file - yes it use .rpt file but it part of the VB.net solution - kind of embeded report like a Form.
I need a sample that will open ANY given file
Main Topics
Browse All TopicsHello experts,
I am trying to create simple report viewer in VB.NET (VS 2003)
I put CRViewer control on the form and trying to assign .rpt file name to the ReportSource property
But it doesn't work - i get message "Load report failed."
I tried to download sample applications from BusinessObects Support site but all samples are using "build-in" reports. and I need to open .rpt file from the disk.
Please help.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
The reports are designed in CR10 (not .NET). The viewer that I am trying to create should be installed on client computers without CR installed. This might be problem by itself. but I cant make it work on my developer machine with CR 10 Pro installed
The code I am using is simple
I have a form with CRViewer control on it.
When user choose File->Open from menu I show standart Open File dialog and assign the resulting filename to ReportSource Property of CRViewer
Private Sub mnuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileOpen.Click
Dim FileName As String
If dlgOpenReport.ShowDialog = DialogResult.OK Then
FileName = dlgOpenReport.FileName
Try
CR.ReportSource = FileName
Catch ex As Exception
MsgBox("Cannot open file: " & FileName & ControlChars.CrLf & "Exception: " & ex.Message)
End Try
End If
End Sub
It doesn't throw exception. It show regular message box stating "Load report failed".
BTW I tried to open empty report (template with static text only) and it works!!!
Maybe it database conectivity problem?
The template also have one table and it asks for username and password as expected.
The database is Oracle 10g (through ODBC) if it make a difference
Here's some sample code to view an external rpt in the viewer (crv1) on a Windows form in VB.Net (using VS 2002). Also a routine to login to the report (assumes SQL Server).
Imports CrystalDecisions.CrystalRe
Imports CrystalDecisions.Shared
Private Sub frmReportEngine_Load(ByVal
crReportDocument.Load("C:\
Call LogonReport(crReportDocume
crv1.ReportSource = crReportDocument
Public Sub LogonReport(ByVal rptReport As CrystalDecisions.CrystalRe
Dim strServer As String = ""
Dim strDBase As String = ""
Dim strUID As String = ""
Dim strPWD As String = ""
Dim crReportDocument As New ReportDocument()
Dim crTableLogonInfos As New TableLogOnInfos()
Dim crTableLogonInfo As New TableLogOnInfo()
Dim crTables As Tables
Dim crTable As Table
Dim crSections As Sections
Dim crSection As Section
Dim crReportObjects As ReportObjects
Dim crReportObject As ReportObject
Dim crSubreportObject As SubreportObject
Dim crDataBase As Database
Dim crConnInfo As New ConnectionInfo()
Dim subRepDoc As New ReportDocument()
strServer = YourServer
strDBase = YourDatabase
strUID = YourUserID
strPWD = YourPassword
'Logs into the tables in the report
crReportDocument = rptReport
crDataBase = crReportDocument.Database
crTables = crDataBase.Tables
For Each crTable In crTables
With crConnInfo
.ServerName = strServer
.DatabaseName = strDBase
.UserID = strUID
.Password = strPWD
End With
'MsgBox("REPORT - TableName = " & crTable.Name & "", MsgBoxStyle.OKOnly)
crTableLogonInfo = crTable.LogOnInfo
crTableLogonInfo.Connectio
crTable.ApplyLogOnInfo(crT
crTable.Location = strDBase & ".dbo." & crTable.Name
crTable.ApplyLogOnInfo(crT
Next
'Logs into the tables in the Sub-reports
crSections = crReportDocument.ReportDef
For Each crSection In crSections
crReportObjects = crSection.ReportObjects
For Each crReportObject In crReportObjects
If crReportObject.Kind = ReportObjectKind.Subreport
crSubreportObject = CType(crReportObject, SubreportObject)
subRepDoc = crSubreportObject.OpenSubr
crDataBase = subRepDoc.Database
crTables = crDataBase.Tables
For Each crTable In crTables
With crConnInfo
.ServerName = strServer
.DatabaseName = strDBase
.UserID = strUID
.Password = strPWD
End With
'MsgBox("SUBREPORT - TableName = " & crTable.Name & "", MsgBoxStyle.OKOnly)
crTableLogonInfo = crTable.LogOnInfo
crTableLogonInfo.Connectio
crTable.ApplyLogOnInfo(crT
crTable.Location = strDBase & ".dbo." & crTable.Name
Next
End If
Next
Next
End Sub
Hi janmarini, thank you for posting.
Same thing here:
Private Sub frmReportEngine_Load(ByVal
crReportDocument.Load("C:\
Call LogonReport(crReportDocume
crv1.ReportSource = crReportDocument
.....
Does the rpt file exist in the specified location? >>> YES
Can you view the same report in Crystal? >>> YES
Do you have approprite permissions to the directory? >>> YES It is local hard drive not network location
Check for typos in the report name or path. >>> I am not typing the name - I am choosing it using Open File Dialog
Also it not one but all .rpt files have the issue exept very simple template (see my previous post)
OK I think I understand what is the problem:
When I tried to add one of the reports to my solution it says that it was created with CR version later than installed.
So actually I am trying to open CR10 report with CR.net (which is I believe compatable with CR9).
Is there a solution for this problem?
I cannot upgrate Visual Studio to higher version so don't suggest. Also we are planing to upgrade CR to XI - we need some new features of it (like cascading parameters and so on)
Loading a CR 10 report from VS 2003 shouldn't be a problem. I'm curious, did you ever try just loading a report with a hard-coded path, filename (not using your mnuFileOpen_Click event/Open file dialog)? Are you sure your connection information is correct? Is your ODBC connection using an UNC path or a mapped drive (try UNC)?
Is this problm occurring in your development environment (this is what I've assumed), but you note "I am distributing VS.Net executable and dll that coming with Visual Studio " If you are deploying your app you need to include the merge modules
Here's some info I found on "load report failed" but not sure if it applies to your specific situation, might be worth a look though
Err Msg: "Load Report Failed" when using an untyped report component in .NET
http://support.businessobj
janmarini:
I did try loading report by hard-coding the file name. Even more - I tryed to assign Report Source property in Design mode (not in code) - the result is the same: "Load Report Failed" message
The problm occurring in development environment.
As you can see from my post from Date: 05/31/2006 09:46AM EDT I tryed to implement both methods from the article "Err Msg: "Load Report Failed" when using an untyped report component in .NET"
Update:
I was able to open several reports from my application but some of the reports won't open!!!
So I can assume that everything is OK mith my .NET viewer - the problem is in the reports. All reports running out of the same database. I cannot find any noticable difference.
Anybody has an idea where to look?
Previously you said that all reports have the problem - has something changed with the reports that are now working?
Are there any differences in the reports that work vs. those that don't such as subreports, parameters?
Are you still getting the same error message "Load report failed" for those that don't open.
janmarini,
As I understand from your Profile you should have VS2003 installed.
Could you do me a favor and try to reproduce this issue on your system.
crate te new windows app and paste following code:
[Code]
Imports CrystalDecisions.CrystalRe
Imports CrystalDecisions.Shared
Public Class frmCRViewer
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.ICon
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents CR As CrystalDecisions.Windows.F
Friend WithEvents mnuMain As System.Windows.Forms.MainM
Friend WithEvents mnuFile As System.Windows.Forms.MenuI
Friend WithEvents mnuFileOpen As System.Windows.Forms.MenuI
Friend WithEvents mnuFileSep1 As System.Windows.Forms.MenuI
Friend WithEvents mnuFileExit As System.Windows.Forms.MenuI
Friend WithEvents dlgOpenReport As System.Windows.Forms.OpenF
<System.Diagnostics.Debugg
Me.CR = New CrystalDecisions.Windows.F
Me.mnuMain = New System.Windows.Forms.MainM
Me.mnuFile = New System.Windows.Forms.MenuI
Me.mnuFileOpen = New System.Windows.Forms.MenuI
Me.mnuFileSep1 = New System.Windows.Forms.MenuI
Me.mnuFileExit = New System.Windows.Forms.MenuI
Me.dlgOpenReport = New System.Windows.Forms.OpenF
Me.SuspendLayout()
'
'CR
'
Me.CR.ActiveViewIndex = -1
Me.CR.Anchor = CType((((System.Windows.Fo
Or System.Windows.Forms.Ancho
Or System.Windows.Forms.Ancho
Me.CR.Location = New System.Drawing.Point(0, 0)
Me.CR.Name = "CR"
Me.CR.ReportSource = Nothing
Me.CR.Size = New System.Drawing.Size(680, 528)
Me.CR.TabIndex = 0
'
'mnuMain
'
Me.mnuMain.MenuItems.AddRa
'
'mnuFile
'
Me.mnuFile.Index = 0
Me.mnuFile.MenuItems.AddRa
Me.mnuFile.Text = "&File"
'
'mnuFileOpen
'
Me.mnuFileOpen.Index = 0
Me.mnuFileOpen.Shortcut = System.Windows.Forms.Short
Me.mnuFileOpen.Text = "&Open ..."
'
'mnuFileSep1
'
Me.mnuFileSep1.Index = 1
Me.mnuFileSep1.Text = "-"
'
'mnuFileExit
'
Me.mnuFileExit.Index = 2
Me.mnuFileExit.Text = "E&xit"
'
'dlgOpenReport
'
Me.dlgOpenReport.DefaultEx
Me.dlgOpenReport.Filter = "Crystal Reports files (*.rpt)|*.rpt"
'
'frmCRViewer
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(680, 526)
Me.Controls.Add(Me.CR)
Me.Menu = Me.mnuMain
Me.Name = "frmCRViewer"
Me.Text = "Crystal Reports Viewer"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub mnuFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileOpen.Click
Dim FileName As String
If dlgOpenReport.ShowDialog = DialogResult.OK Then
FileName = dlgOpenReport.FileName
Try
CR.ReportSource = FileName
Catch ex As Exception
MsgBox("Cannot open file: " & FileName & ControlChars.CrLf & "Exception: " & ex.Message)
End Try
End If
End Sub
End Class
[/Code]
Try to open a report without Custom Function
It should open just fine
Then modify the report by adding a Custom Function - you dont have to use it anywhere on the report - just define one.
Try to open the report again in Viewer.
BANG!!! Or not?
I tried your code and you are very correct - it IS the custom function causing the problem.
I can open a report that does not contain a custom function.
I added a custom function to the report and used it is a formula field. Could not load report.
I deleted the formula field using the custom function. Could not load report.
I deleted the custom function from the report and then could open the report.
The report I tested with was created with CR 9.0. Fursther details on the load error indicated that the report was created with a version of Crystal Reports which is later that the version you are running (VS 2003) ...misleading message because this is not true, rather it seems the VS 2003 does not support the use of custom functions....
I'll see if I can find any additional info regarding this issue.
In the worst case I think you could remove the custom functions from the reports and use regular fomulas instead.
Closest additional info I could find is the following link. I didn't have time to check it out because I have to get to work. When I tested your code I created the report (and repository) on 1 machine (that has CR 9) then copied to the report file to another machine (that has VS 2003)...Perhaps it didn't work because I didn't have the repository (or connection) on the machine with VS 2003. Never have used the repository (or custom functions before) so I don't know if this info will be helpful or not
Err Msg: "Load Report Failed" when using Business Views in VS .NET application .... Applies to CR10.0 -Business View and other Repository objects (which includes custom functions) - sounds like some repository (CE) connection info is needed...
http://support.businessobj
The repository is where the custom functions are created and stored in Crystal Reports, not Crystal Enterprise. I think the reference to Crystal Enterprise is a little confusing....
The link I sent to you specifically deals with CR 10 - it refers to the EnterpriseSession property of the ReportDocument object.
You may want to read up a little on Repository objects - which include custom functions. You might also want to try adding in the few lines of code suggested in the solution (convert to VB, example is C#). You may have to add a reference to the CrystalEnterpriseLib (Project/Add Refererence/CrystalEnterpr
Imports CrystalEnterpriseLib
Business Accounts
Answer for Membership
by: ast2550Posted on 2006-05-30 at 13:37:35ID: 16793470
Download ects.com/c ommunityCS / FilesAndU pdates/vbn et_win_sam ples.exe.a sp
ort.zip from within the distribution and it had an .rpt file, so it should be what you want.
http://support.businessobj
I opened vbnet_win_SimplePreviewRep