?
Solved

Simple report viewer VB.Net

Posted on 2006-05-30
32
Medium Priority
?
40,894 Views
Last Modified: 2011-08-18
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.
0
Comment
Question by:Michael_D
  • 18
  • 9
  • 4
  • +1
32 Comments
 
LVL 7

Expert Comment

by:ast2550
ID: 16793470
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
 
LVL 13

Author Comment

by:Michael_D
ID: 16793497
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
 
LVL 101

Expert Comment

by:mlmcc
ID: 16795515
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 13

Author Comment

by:Michael_D
ID: 16798404
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
 
LVL 7

Expert Comment

by:janmarini
ID: 16798456
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
 
LVL 13

Author Comment

by:Michael_D
ID: 16798528
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
 
LVL 7

Expert Comment

by:janmarini
ID: 16798604
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
 
LVL 13

Author Comment

by:Michael_D
ID: 16798670
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
 
LVL 7

Expert Comment

by:janmarini
ID: 16798971
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
 
LVL 13

Author Comment

by:Michael_D
ID: 16799073
janmarini,

I do verify the file name - it is correct, fully qualified filename (with a path and extention).
0
 
LVL 13

Author Comment

by:Michael_D
ID: 16799212
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
 
LVL 13

Author Comment

by:Michael_D
ID: 16799443
I have installed latest service pack for CR.net but it doesn't help.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 16804170
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
 
LVL 13

Author Comment

by:Michael_D
ID: 16806961
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
 
LVL 101

Expert Comment

by:mlmcc
ID: 16812214
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
 
LVL 7

Expert Comment

by:janmarini
ID: 16812806
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
 
LVL 13

Author Comment

by:Michael_D
ID: 16816526
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
 
LVL 13

Author Comment

by:Michael_D
ID: 16816735
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
 
LVL 13

Author Comment

by:Michael_D
ID: 16816773
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
 
LVL 7

Expert Comment

by:janmarini
ID: 16816781
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
 
LVL 13

Author Comment

by:Michael_D
ID: 16816821
>>Previously you said that all reports have the problem >> Yes but I am creating new reports :)


0
 
LVL 7

Expert Comment

by:janmarini
ID: 16816834
Can you post an example of your custom function
0
 
LVL 13

Author Comment

by:Michael_D
ID: 16816851
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
 
LVL 13

Author Comment

by:Michael_D
ID: 16817098
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
 
LVL 7

Accepted Solution

by:
janmarini earned 1500 total points
ID: 16818334
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
 
LVL 13

Author Comment

by:Michael_D
ID: 16818913
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
 
LVL 7

Expert Comment

by:janmarini
ID: 16819159

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
 
LVL 13

Author Comment

by:Michael_D
ID: 16819384
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
 
LVL 101

Expert Comment

by:mlmcc
ID: 16821610
Where are you creating the custom function?

mlmcc
0
 
LVL 13

Author Comment

by:Michael_D
ID: 16832552
>>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
 
LVL 7

Expert Comment

by:janmarini
ID: 16833649
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
 
LVL 13

Author Comment

by:Michael_D
ID: 16934718
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question