Link to home
Start Free TrialLog in
Avatar of alexking
alexkingFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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

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

ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of alexking

ASKER

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.