Click here to Skip to main content
15,892,575 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i got an error (Load report fialed) when trying to print crystal report in my vb.net application but my problem is (This error isn't always come, this suddenly comes after some reports printed correctly) maybe after print unknown number of reports, then one time this error comes. here is my code:

What I have tried:

VB
Dim cmd As New OleDbCommand
    Dim connp As New OleDbConnection
    Dim da As New OleDbDataAdapter
    Dim ds As New DataSet
    Dim strsql As String
    Dim strreprotname As String
    Try
        connp.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\report.mdb; Jet OLEDB:Database Password=KNOZ1003"
        connp.Open()
        ds.Reset()
        strsql = "select * from tab3"
        cmd.CommandText = strsql
        cmd.Connection = connp
        da.SelectCommand = cmd
        da.Fill(ds)
        strreprotname = "cashrpt"
        Dim strreportpath As String = Application.StartupPath & "\Reports\" & strreprotname & ".rpt"
        Dim rptdocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument
        Dim prnset As New Printing.PrinterSettings
        Dim pg As New Printing.PageSettings
        rptdocument.Load(strreportpath)
        rptdocument.SetDataSource(ds.Tables(0))
        rptdocument.SetDatabaseLogon("", "", "", Application.StartupPath + "\report.mdb")
        prnset.PrinterName = cashprinter
        rptdocument.PrintToPrinter(prnset, pg, False)
        cmd.Dispose()
        connp.Close()
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
Posted
Updated 21-Mar-16 14:21pm
Comments
Richard MacCutchan 19-Mar-16 8:27am    
Try using different names for your report rather than the same name each time. It may be that you are having file access issues.

1 solution

You are not closing off your Report Document.
Add the following;
VB
rptdocument.Close()
rptdocument.Dispose()

If you have a look at Task Manager, you will likely find a lot of Crystal Reports instances running. They will eventually close themselves but it is much better practice to close them yourself when you are finished with them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900