?
Solved

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

Posted on 2008-10-27
2
Medium Priority
?
1,242 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
[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
2 Comments
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Hello everyone, Hope you find this as helpful as we did. We have on the company I work for an application built in Delphi V with Crystal Reports 8. We all know that Crystal & Delphi can be temperamental sometimes and the worst thing is, nearly…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
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…
Suggested Courses

765 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