Unable to release the Crystal Report in Asp.net

Source: Internet
Author: User

Symptom:

Recently, Crystal Reports have been used in the program to generate PDF documents using Crystal Reports on a page. The program runs well, but there is a strange problem: after running the program for a while, you must restart IIS.

Analysis process:

I used Process Explorer to check the IIS Process and found that many files were not released in the Process. For example:

 

IIS processes are flooded with temporary files that are not released.

Solution:

In the page event Page_Unload that uses the Crystal Report, release the object related to the crystal report.

 

1 Imports DataBean
2 Imports DataSet1
3 Imports System. Data
4 Imports CrystalDecisions. CrystalReports. Engine
5 Imports CrystalDecisions. Shared
6
7 Partial Class _ CrystallReportTestingClass _ CrystallReportTesting
8 Inherits System. Web. UI. Page
9
10 Dim oRpt As New ReportDocument
11 Protected Sub Page_Load () Sub Page_Load (ByVal sender As Object, ByVal e As System. EventArgs) Handles Me. Load
12 ''crystal report binding
13 oRpt. Load (Server. MapPath ("CrystalReport4.rpt "))
14 oRpt. SetDataSource (getperformancefromoracle ())
15 ''set ReportSource FOR THE CRYSTAL REPORT
16 CrystalReportViewer1.ReportSource = oRpt
17 End Sub
18
19 Protected Sub Page_Unload () Sub Page_Unload (ByVal sender As Object, ByVal e As System. EventArgs) Handles Me. Unload
20 oRpt. Close () ''release the crystal report object
21 oRpt. Dispose ()
22 System. GC. Collect (0)
23 End Sub
24End Class
25

 

Episode:

During the debugging process, I found that after the Page_Load event is executed every time the page is loaded (if there is no other code), the Page_Unload event will be executed immediately. What's going on? I intuitively thought that Page_Unload will be triggered when the client closes the webpage.

This is also the main reason for recording this event: I often do not naturally understand the Web programming mode as the Windows programming mode. Forget the stateless nature of http. Subjective assumption: without thinking, the Page_Unload will be triggered when the client closes the webpage-how can this happen? For the Asp.net execution model, when IIS receives a Get/Post request, it initializes an access-related page class to process the request. The HTML generated after processing is sent back to the client, and the page class waits for garbage collection.

After sending a reply to the Internet, I answered the following question:

It's confusing for windows developer. remember about Unload event defenition. "Occurs when the server control is unloaded from memory" after each load or post back in server side all controls Unloaded from memory. remember we talking about web application all controls get alived by request and died when response create and send to client. so thats why after load event Unload event called.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.