Solved

Failed to load report error using crystal reports and vb.net

Posted on 2008-10-27
2
1,236 Views
Last Modified: 2011-10-03
I am using a crystal reports that ships with visual studio.net to create customer accounts and after printing 67 reports to disc it is blowing out with "Load Report Failed" on the line cryRpt.Load(strReportName)

I think perhaps I am not closing something or disposing of something, the code I am using is attached - I loop over my customer set (of about 300) and call this routine every time. My report is linked to a table in sql server 2005.

Private Sub ConfigureInvoiceAccRunRpt()
 
        Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
        Dim strReportName As String = ""
        Try
 
            myConnectionInfo.AllowCustomConnection = True
            myConnectionInfo.DatabaseName = "MyDb"
            myConnectionInfo.ServerName = MyServerName
            myConnectionInfo.IntegratedSecurity = True
            myConnectionInfo.Type = ConnectionInfoType.SQL
 
            strReportName = "C:\Invoice.rpt"
 
            Dim cryRpt As New ReportDocument
            cryRpt.Load(strReportName)  '<-- fails here after 67 times
 
            SetDBLogonForReport(myConnectionInfo, cryRpt)
 
            Dim crParameterFieldDefinitions As ParameterFieldDefinitions
            Dim crParameterFieldDefinition As ParameterFieldDefinition
            Dim crParameterValues As New ParameterValues
            Dim crParameterDiscreteValue As New ParameterDiscreteValue
 
            crParameterValues.Clear()
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
 
            crParameterDiscreteValue.Value = 3
            crParameterFieldDefinition = crParameterFieldDefinitions.Item("SiteID")
            crParameterValues = crParameterFieldDefinition.CurrentValues
            crParameterValues.Add(crParameterDiscreteValue)
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
           
             cryRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.CrystalReport, "C:\Spool\Accounts\Customername.rpt")
 
        Catch
            MsgBox(Err.Description)
        Finally
        End Try
 
    End Sub

Open in new window

0
Comment
Question by:alexking
2 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 500 total points
ID: 22811559
I had the very same problem (except that my trigger was at 75). I ended fixing the problem by calling all the appropriate Dispose and Close methods on each object that was having them and setting my objects to Nothing.

Try something like this:

    Private Sub ConfigureInvoiceAccRunRpt()
 
        Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
        Dim strReportName As String = ""
 
        Dim cryRpt As New ReportDocument
 
        Try
 
            myConnectionInfo.AllowCustomConnection = True
            myConnectionInfo.DatabaseName = "MyDb"
            myConnectionInfo.ServerName = MyServerName
            myConnectionInfo.IntegratedSecurity = True
            myConnectionInfo.Type = ConnectionInfoType.SQL
 
            strReportName = "C:\Invoice.rpt"
 
            cryRpt.Load(strReportName)  '<-- fails here after 67 times
 
            SetDBLogonForReport(myConnectionInfo, cryRpt)
 
            Dim crParameterFieldDefinitions As ParameterFieldDefinitions
            Dim crParameterFieldDefinition As ParameterFieldDefinition
            Dim crParameterValues As New ParameterValues
            Dim crParameterDiscreteValue As New ParameterDiscreteValue
 
            crParameterValues.Clear()
            crParameterFieldDefinitions = cryRpt.DataDefinition.ParameterFields
 
            crParameterDiscreteValue.Value = 3
            crParameterFieldDefinition = crParameterFieldDefinitions.Item("SiteID")
            crParameterValues = crParameterFieldDefinition.CurrentValues
            crParameterValues.Add(crParameterDiscreteValue)
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues)
 
            cryRpt.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.CrystalReport, "C:\Spool\Accounts\Customername.rpt")
 
        Catch
            MsgBox(Err.Description)
        Finally
            cryRpt.Close()
            cryRpt.Dispose()
            cryRpt = Nothing
 
            myConnectionInfo = Nothing
        End Try
    End Sub

Open in new window

0
 

Author Comment

by:alexking
ID: 22811634
Many thanks - its hard to find much documentation about this, seems to be a well kept secret! I only traced the error by using the activity monitor in SQL server management studio in the first place.

0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Optimize the query 5 55
Crystal Reports - Record selection filter - formula editor 3 39
Visual studio 2015 1 36
VB.net Duplicating a table - primary key not created 3 38
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…
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 …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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