Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How do You Export Crystal Report to PDF Without Writing to File and With no Memory Issues?

Posted on 2004-10-01
4
Medium Priority
?
5,470 Views
Last Modified: 2012-06-21
Hello,

I am using Visual Studio .NET 2002.  I have a Crystal Report in my folder, which gets dynamically populated.  The code I have right now displays the report as a PDF without writing a file to the server:

        Dim strConn As String
        Dim SQL As String
       
        strConn = ConfigurationSettings.AppSettings("ConnectString4")
        Dim conn As New OleDbConnection(strConn)

        Dim strPermit As String
        strPermit = Request.QueryString("SWP")
 
        SQL = "SELECT * from VW_SWP where swp_id=" & strPermit
 
        Dim da As New OleDbDataAdapter(SQL, conn)
        da = New OleDbDataAdapter(SQL, conn)

        Dim rpt As CrystalReport1 = New CrystalReport1()

        Dim dt As New DataTable()

        da.Fill(dt)

        rpt.SetDataSource(dt)
       
        CrystalReportViewer1.ReportSource = rpt

        conn.Close()
        conn.Dispose()
        dt.Dispose()

  Dim crExportOptions As ExportOptions

        crExportOptions = rpt.ExportOptions
        With crExportOptions
            .FormatOptions = New PdfRtfWordFormatOptions()
            .ExportFormatType = ExportFormatType.PortableDocFormat
        End With

        Dim req As ExportRequestContext = New ExportRequestContext()
        req.ExportInfo = crExportOptions

        Dim st As System.IO.Stream
        st = rpt.FormatEngine.ExportToStream(req)

        rpt = Nothing

        Response.ClearContent()
        Response.ClearHeaders()
        Response.ContentType = "application/pdf"

        Dim b(st.Length) As Byte

        st.Read(b, 0, st.Length)

        Response.BinaryWrite(b)

        st.Close()
        st = Nothing

        CrystalReportViewer1.Dispose()

        Response.End()

The problem I am having is that everytime the export code gets executed it adds a few MBs to the ASP.NET worker process, and once this gets to about 150 MB the line:   rpt.SetDataSource(dt)
stalls, and therefore the web page never loads, so the report is not shown.  Is there something I'm not disposing of so I have a memory leak, or is there a better way to do this?  And why would the  rpt.SetDataSource(dt) line fail when the worker process is only at 150 MB?  I would think that this is relatively low...Thanks for your help!



Grant
0
Comment
Question by:gcarelse
[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
  • 2
4 Comments
 
LVL 42

Accepted Solution

by:
frodoman earned 2000 total points
ID: 12202104
I don't see where you're disposing your data adapter [ da.dispose() ] but garbage collection should be handling that so I doubt that's the problem.

Have you applied the VS2002 service pack from Crystal?  It did address some memory leaks - not sure if this was one of them or not.  If you haven't done so you can get the SP here: http://support.businessobjects.com/fix/hot/si75/default.asp?ref=default.asp_wwwjump#Crystal%20Reports%20Service%20Packs

frodoman
0
 

Author Comment

by:gcarelse
ID: 12203136
Hey there frodoman,

I'm not sure if our server guys have applied the VS2002 service pack from Crystal.  I'll get them to download it, and I'll let you know if it solved my problem or not, once they've applied it.  Thanks for the pointer.


Grant
0
 

Author Comment

by:gcarelse
ID: 12301821
Yep, the VS2002 service pack from Crystal solved the problem.  Thanks!


Grant
0
 
LVL 42

Expert Comment

by:frodoman
ID: 12301870
Glad to help - frodoman
0

Featured Post

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

721 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