Meeskas
asked on
Printing Multiple Reports using .NET 2005 and Crystal
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 CrystalActiveXReportViewer Lib11_5.Re portSource Router = New CrystalActiveXReportViewer Lib11_5.Re portSource RouterClas s()
Dim bPrintCalled As Boolean = False
Friend WithEvents CrystalViewer As AxCrystalActiveXReportView erLib11_5. AxCrystalA ctiveXRepo rtViewer
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 CrystalActiveXReportViewer Lib11_5.Re portSource RouterClas s
'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 tainer
'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.TextB ox
<System.Diagnostics.Debugg erStepThro ugh()> Private Sub InitializeComponent()
Dim resources As System.ComponentModel.Comp onentResou rceManager = New System.ComponentModel.Comp onentResou rceManager (GetType(f rmPrintJob ))
Me.txtStatus = New System.Windows.Forms.TextB ox
Me.CrystalViewer = New AxCrystalActiveXReportView erLib11_5. AxCrystalA ctiveXRepo rtViewer
CType(Me.CrystalViewer, System.ComponentModel.ISup portInitia lize).Begi nInit()
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.Scrol lBars.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( "CrystalVi ewer.OcxSt ate"), System.Windows.Forms.AxHos t.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.Crystal Viewer)
Me.Controls.Add(Me.txtStat us)
Me.FormBorderStyle = System.Windows.Forms.FormB orderStyle .FixedSing le
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "frmPrintJob"
Me.StartPosition = System.Windows.Forms.FormS tartPositi on.CenterS creen
Me.Text = "Print Statements"
Me.TopMost = True
CType(Me.CrystalViewer, System.ComponentModel.ISup portInitia lize).EndI nit()
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(Tr ue)
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.Unsaf eNativeMet hods.CallW indowProc( IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.Nativ eWindow.De fWndProc(M essage& m)
at System.Windows.Forms.Contr ol.DefWndP roc(Messag e& m)
at System.Windows.Forms.Contr ol.WndProc (Message& m)
at System.Windows.Forms.AxHos t.WndProc( Message& m)
at System.Windows.Forms.Contr ol.Control NativeWind ow.OnMessa ge(Message & m)
at System.Windows.Forms.Contr ol.Control NativeWind ow.WndProc (Message& m)
at System.Windows.Forms.Nativ eWindow.De buggableCa llback(Int Ptr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.Unsaf eNativeMet hods.Dispa tchMessage W(MSG& msg)
at System.Windows.Forms.Appli cation.Com ponentMana ger.System .Windows.F orms.Unsaf eNativeMet hods.IMsoC omponentMa nager.FPus hMessageLo op(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Appli cation.Thr eadContext .RunMessag eLoopInner (Int32 reason, ApplicationContext context)
at System.Windows.Forms.Appli cation.Thr eadContext .RunMessag eLoop(Int3 2 reason, ApplicationContext context)
at System.Windows.Forms.Appli cation.Run Dialog(For m form)
at System.Windows.Forms.Form. ShowDialog (IWin32Win dow owner)
at System.Windows.Forms.Form. ShowDialog ()
Public Class frmPrintJob
Inherits System.Windows.Forms.Form
Dim rsr As CrystalActiveXReportViewer
Dim bPrintCalled As Boolean = False
Friend WithEvents CrystalViewer As AxCrystalActiveXReportView
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 CrystalActiveXReportViewer
'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 txtStatus As System.Windows.Forms.TextB
<System.Diagnostics.Debugg
Dim resources As System.ComponentModel.Comp
Me.txtStatus = New System.Windows.Forms.TextB
Me.CrystalViewer = New AxCrystalActiveXReportView
CType(Me.CrystalViewer, System.ComponentModel.ISup
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.Scrol
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(
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.Crystal
Me.Controls.Add(Me.txtStat
Me.FormBorderStyle = System.Windows.Forms.FormB
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "frmPrintJob"
Me.StartPosition = System.Windows.Forms.FormS
Me.Text = "Print Statements"
Me.TopMost = True
CType(Me.CrystalViewer, System.ComponentModel.ISup
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
CrystalViewer.RefreshEx(Tr
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.Unsaf
at System.Windows.Forms.Nativ
at System.Windows.Forms.Contr
at System.Windows.Forms.Contr
at System.Windows.Forms.AxHos
at System.Windows.Forms.Contr
at System.Windows.Forms.Contr
at System.Windows.Forms.Nativ
at System.Windows.Forms.Unsaf
at System.Windows.Forms.Appli
at System.Windows.Forms.Appli
at System.Windows.Forms.Appli
at System.Windows.Forms.Appli
at System.Windows.Forms.Form.
at System.Windows.Forms.Form.
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 ?
ASKER
Not sure what you mean.
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
You will have to use the .Net viewer and code methods
mlmcc
ASKER
But I have Crystal XI R2 installed. Doesn't that license me to use CRAXDRT?
Yes, with VB6 no longer with .Net.
mlmcc
mlmcc
ASKER
Then why is the CRAXDRT dll included in the XI R2 bin? What are you supposed to use instead?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.