Simple report viewer VB.Net

Hello 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.
LVL 13
Michael_DAsked:
Who is Participating?
 
janmariniConnect With a Mentor Commented:
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.



0
 
ast2550Commented:
Download
http://support.businessobjects.com/communityCS/FilesAndUpdates/vbnet_win_samples.exe.asp

I opened vbnet_win_SimplePreviewReport.zip from within the distribution and it had an .rpt file, so it should be what you want.
0
 
Michael_DAuthor Commented:
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
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
mlmccCommented:
What code are you using?

I don't have the .Net version but that may be a feature that is not available.  Can you save rpt files from the designer?  I assume you are using the version of Crystal that came with CR.Net.  If not then which version of Crystal?

mlmcc
0
 
Michael_DAuthor Commented:
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
0
 
janmariniCommented:
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.CrystalReports.Engine
Imports CrystalDecisions.Shared


Private Sub frmReportEngine_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

crReportDocument.Load("C:\Replace with Your Report Path and Name.rpt", OpenReportMethod.OpenReportByTempCopy)
Call LogonReport(crReportDocument)
crv1.ReportSource = crReportDocument





Public Sub LogonReport(ByVal rptReport As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal strLocation As String)
        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.ConnectionInfo = crConnInfo
            crTable.ApplyLogOnInfo(crTableLogonInfo)
            crTable.Location = strDBase & ".dbo." & crTable.Name
            crTable.ApplyLogOnInfo(crTableLogonInfo)
        Next

        'Logs into the tables in the Sub-reports
        crSections = crReportDocument.ReportDefinition.Sections
        For Each crSection In crSections
            crReportObjects = crSection.ReportObjects
            For Each crReportObject In crReportObjects
                If crReportObject.Kind = ReportObjectKind.SubreportObject Then
                    crSubreportObject = CType(crReportObject, SubreportObject)
                    subRepDoc = crSubreportObject.OpenSubreport(crSubreportObject.SubreportName)
                    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.ConnectionInfo = crConnInfo
                        crTable.ApplyLogOnInfo(crTableLogonInfo)
                        crTable.Location = strDBase & ".dbo." & crTable.Name
                    Next
                End If
            Next
        Next
    End Sub

0
 
Michael_DAuthor Commented:
Hi janmarini, thank you for posting.

Same thing here:

Private Sub frmReportEngine_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

crReportDocument.Load("C:\Replace with Your Report Path and Name.rpt", OpenReportMethod.OpenReportByTempCopy)  '<---- Throw exception "Load report failed"
Call LogonReport(crReportDocument)
crv1.ReportSource = crReportDocument

.....
0
 
janmariniCommented:
Does the rpt file exist in the specified location?
Can you view the same report in Crystal?
Do you have approprite permissions to the directory?
Check for typos in the report name or path.
0
 
Michael_DAuthor Commented:
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)
0
 
janmariniCommented:
Have you tried testing opening your report by hard-coding your report location?  Your problem might be with your Open file diaplog - have you verified that it passes the proper report *PATH* and filename (FileName = dlgOpenReport.FileName)?
0
 
Michael_DAuthor Commented:
janmarini,

I do verify the file name - it is correct, fully qualified filename (with a path and extention).
0
 
Michael_DAuthor Commented:
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)
0
 
Michael_DAuthor Commented:
I have installed latest service pack for CR.net but it doesn't help.
0
 
mlmccCommented:
If you only have the CR 10 Professional Edition, you don't haev a license oto distribute the CR viewing dlls.  You need at least the Developer edition.

mlmcc
0
 
Michael_DAuthor Commented:
mlmcc - I don't have to use CR10's license - I am distributing VS.Net executable and dll that coming with Visual Studio - correct me if I am wrong
0
 
mlmccCommented:
You might be correct but the CR.Net licenses may only apply to CR.Net and not CR 10.

I don't have CR.Net or 10 so I can't check.

mlmcc
0
 
janmariniCommented:
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.businessobjects.com/library/kbase/articles/c2014070.asp
0
 
Michael_DAuthor Commented:
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"


 

0
 
Michael_DAuthor Commented:
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?
 
0
 
Michael_DAuthor Commented:
Hehe - got it!!!

Any report that contain "Report Custom Function" fail to load in CRViewer component for .NET

Anybody knows how to resolve it?
0
 
janmariniCommented:
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.
0
 
Michael_DAuthor Commented:
>>Previously you said that all reports have the problem >> Yes but I am creating new reports :)


0
 
janmariniCommented:
Can you post an example of your custom function
0
 
Michael_DAuthor Commented:
Any function will cause the problem even if it is only defined and never used

Here is a sample of one I use:
Function pad( s as string, l as number ) as string
    pad=Left(s & space(l), l)  
End Function
0
 
Michael_DAuthor Commented:
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.CrystalReports.Engine
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.IContainer

    '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.Forms.CrystalReportViewer
    Friend WithEvents mnuMain As System.Windows.Forms.MainMenu
    Friend WithEvents mnuFile As System.Windows.Forms.MenuItem
    Friend WithEvents mnuFileOpen As System.Windows.Forms.MenuItem
    Friend WithEvents mnuFileSep1 As System.Windows.Forms.MenuItem
    Friend WithEvents mnuFileExit As System.Windows.Forms.MenuItem
    Friend WithEvents dlgOpenReport As System.Windows.Forms.OpenFileDialog
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.CR = New CrystalDecisions.Windows.Forms.CrystalReportViewer
        Me.mnuMain = New System.Windows.Forms.MainMenu
        Me.mnuFile = New System.Windows.Forms.MenuItem
        Me.mnuFileOpen = New System.Windows.Forms.MenuItem
        Me.mnuFileSep1 = New System.Windows.Forms.MenuItem
        Me.mnuFileExit = New System.Windows.Forms.MenuItem
        Me.dlgOpenReport = New System.Windows.Forms.OpenFileDialog
        Me.SuspendLayout()
        '
        'CR
        '
        Me.CR.ActiveViewIndex = -1
        Me.CR.Anchor = CType((((System.Windows.Forms.AnchorStyles.Top Or System.Windows.Forms.AnchorStyles.Bottom) _
                    Or System.Windows.Forms.AnchorStyles.Left) _
                    Or System.Windows.Forms.AnchorStyles.Right), System.Windows.Forms.AnchorStyles)
        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.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFile})
        '
        'mnuFile
        '
        Me.mnuFile.Index = 0
        Me.mnuFile.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.mnuFileOpen, Me.mnuFileSep1, Me.mnuFileExit})
        Me.mnuFile.Text = "&File"
        '
        'mnuFileOpen
        '
        Me.mnuFileOpen.Index = 0
        Me.mnuFileOpen.Shortcut = System.Windows.Forms.Shortcut.F2
        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.DefaultExt = "rpt"
        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?

0
 
Michael_DAuthor Commented:
I couldn't find any usefull info on BO's site so I am going to get rid of Custom functions
Unfortunately you can't just replase Custom function with formula - I am using input parameters which is impossible in formulas.
0
 
janmariniCommented:

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.businessobjects.com/library/kbase/articles/c2014526.asp?ref=devzone_netzone_archive
0
 
Michael_DAuthor Commented:
The repository is part of Crystal Enterprize I guess and I am not using it. I am using (OK - was using) Report Custom Functions. There is no logon credentials involved so this link is not applicable to my situation.
0
 
mlmccCommented:
Where are you creating the custom function?

mlmcc
0
 
Michael_DAuthor Commented:
>>Where are you creating the custom function?
What do you mean by Where?
All reports are build in CR10 (not .NET)

We don't have Enterprise Edition hence I cannot store my functions in centralized repository and i am stuck to Report based functions
0
 
janmariniCommented:
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/CrystalEnterpriseLib) and on your VB Form,
Imports CrystalEnterpriseLib
0
 
Michael_DAuthor Commented:
I am assuming that there is no solution and in order to use reports in CR Viewer Control for .NET the report cannot contain Custom Functions.
I am accepting janmarini's comment because he spend so much time with me analysing and testing.

Thank you all, guys

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.