Solved

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

Posted on 2008-10-27
2
1,218 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 69

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now