gcarelse
asked on
How do You Export Crystal Report to PDF Without Writing to File and With no Memory Issues?
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.AppS ettings("C onnectStri ng4")
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.Repor tSource = rpt
conn.Close()
conn.Dispose()
dt.Dispose()
Dim crExportOptions As ExportOptions
crExportOptions = rpt.ExportOptions
With crExportOptions
.FormatOptions = New PdfRtfWordFormatOptions()
.ExportFormatType = ExportFormatType.PortableD ocFormat
End With
Dim req As ExportRequestContext = New ExportRequestContext()
req.ExportInfo = crExportOptions
Dim st As System.IO.Stream
st = rpt.FormatEngine.ExportToS tream(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.Dispo se()
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
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.AppS
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.Repor
conn.Close()
conn.Dispose()
dt.Dispose()
Dim crExportOptions As ExportOptions
crExportOptions = rpt.ExportOptions
With crExportOptions
.FormatOptions = New PdfRtfWordFormatOptions()
.ExportFormatType = ExportFormatType.PortableD
End With
Dim req As ExportRequestContext = New ExportRequestContext()
req.ExportInfo = crExportOptions
Dim st As System.IO.Stream
st = rpt.FormatEngine.ExportToS
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.Dispo
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yep, the VS2002 service pack from Crystal solved the problem. Thanks!
Grant
Grant
Glad to help - frodoman
ASKER
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