Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Printing Multiple Reports using .NET 2005 and Crystal

Posted on 2012-04-04
8
Medium Priority
?
568 Views
Last Modified: 2012-04-11
I have an application that has a requirement to print multiple reports as one.  It will print one report.  When I add a second report, it will print the first report, then it logs a memory error.  I am thinking that maybe there is a property not set right.  Below is the code, then the error message.  Any help would be greatly apprecialted.  Using .NET 2005 and Crystal XI R2.

Public Class frmPrintJob
    Inherits System.Windows.Forms.Form

    Dim rsr As CrystalActiveXReportViewerLib11_5.ReportSourceRouter = New CrystalActiveXReportViewerLib11_5.ReportSourceRouterClass()
    Dim bPrintCalled As Boolean = False
    Friend WithEvents CrystalViewer As AxCrystalActiveXReportViewerLib11_5.AxCrystalActiveXReportViewer

    Dim last_msg As String = "<>"

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()
        rsr = New CrystalActiveXReportViewerLib11_5.ReportSourceRouterClass
        '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 txtStatus As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmPrintJob))
        Me.txtStatus = New System.Windows.Forms.TextBox
        Me.CrystalViewer = New AxCrystalActiveXReportViewerLib11_5.AxCrystalActiveXReportViewer
        CType(Me.CrystalViewer, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'txtStatus
        '
        Me.txtStatus.ForeColor = System.Drawing.Color.Navy
        Me.txtStatus.Location = New System.Drawing.Point(8, 8)
        Me.txtStatus.Multiline = True
        Me.txtStatus.Name = "txtStatus"
        Me.txtStatus.ScrollBars = System.Windows.Forms.ScrollBars.Both
        Me.txtStatus.Size = New System.Drawing.Size(408, 112)
        Me.txtStatus.TabIndex = 2
        Me.txtStatus.Text = "_Status"
        '
        'CrystalViewer
        '
        Me.CrystalViewer.Enabled = True
        Me.CrystalViewer.Location = New System.Drawing.Point(428, 135)
        Me.CrystalViewer.Name = "CrystalViewer"
        Me.CrystalViewer.OcxState = CType(resources.GetObject("CrystalViewer.OcxState"), System.Windows.Forms.AxHost.State)
        Me.CrystalViewer.Size = New System.Drawing.Size(711, 592)
        Me.CrystalViewer.TabIndex = 0
        '
        'frmPrintJob
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(1365, 621)
        Me.ControlBox = False
        Me.Controls.Add(Me.CrystalViewer)
        Me.Controls.Add(Me.txtStatus)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.MaximizeBox = False
        Me.MinimizeBox = False
        Me.Name = "frmPrintJob"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "Print Statements"
        Me.TopMost = True
        CType(Me.CrystalViewer, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub

#End Region
    Public Sub add_status(ByVal desc As String)
        If last_msg <> desc Then
            txtStatus.AppendText(desc & vbCrLf)
            last_msg = desc
        End If

    End Sub

    <CLSCompliant(False)> Public Sub add_report(ByVal r As CRAXDRT.Report)
        add_status("    Adding - " & r.ReportTitle)
        rsr.AddReport(r)
    End Sub

    Public Sub show_reports()
        CrystalViewer.ReportSource = rsr
        CrystalViewer.RefreshEx(True)
        add_status("Refreshing Data")
        CrystalViewer.ViewReport()

    End Sub


Here is the error message from the log:

4/4/2012 10:48:22 AM EXCEPTION REPORTED
Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
   at System.Windows.Forms.Control.DefWndProc(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.AxHost.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
   at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
   at System.Windows.Forms.Application.RunDialog(Form form)
   at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
   at System.Windows.Forms.Form.ShowDialog()
0
Comment
Question by:Meeskas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 18

Expert Comment

by:vasto
ID: 37808119
You are using .NET with Crystal reports COM objects.  I can see "UnsafeNativeMethods" in the provided  error message. Did you try to use managed components instead ?
0
 
LVL 1

Author Comment

by:Meeskas
ID: 37808820
Not sure what you mean.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 37808971
The dll CRAXDRT is a COM dll and is not licensed for use with .Net applications.

You will have to use the .Net viewer and code methods

mlmcc
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Meeskas
ID: 37812931
But I have Crystal XI R2 installed.  Doesn't that license me to use CRAXDRT?
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 37814782
Yes, with VB6 no longer with .Net.  

mlmcc
0
 
LVL 1

Author Comment

by:Meeskas
ID: 37815220
Then why is the CRAXDRT dll included in the XI R2 bin?  What are you supposed to use instead?
0
 
LVL 101

Accepted Solution

by:
mlmcc earned 2000 total points
ID: 37818157
It is there for some kind of compatibility.  In further reading, CRAXDDRT is actually used by the .Net IDE to allow you to design reports.


http://www.sdn.sap.com/irj/boc/go/portal/prtroot/docs/library/uuid/e0eb394f-931e-2b10-3b82-9413bfc3f457?QuickLink=index&overridelayout=true&29669634095258

CRAXDRT is included with CR XI so you can use it in VB6 applications.

mlmcc
0
 
LVL 1

Author Comment

by:Meeskas
ID: 37834973
Thanks for your help and the links to the documentation.  I basically recoded everything to use ReportDocument instead of CRAXDRT and to use only the .NET assemblies.  Everything works now.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

705 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