excel export giving memory error
Hi
I am exporting the data to excel.If i have huge data its giving memroy error means it creates an enormous amount of objects in memory and the .Net framework restarts the asp.net process to prevent it from eating all the server's memory.
This means that all asp.net applications running on that server would be restarted (loosing connections, sessions data...)
log shows below error
aspnet_wp.exe (PID: 2616) was recycled because memory consumption exceeded the 305 MB (60 percent of available RAM).
my code is
Dim adapter As New SqlDataAdapter(sql, con) '
Dim myDataSet As New DataSet
Try
adapter.Fill(myDataSet, "ds")
Catch ex As Exception
End Try
Response.Clear()
Response.Charset = ""
Response.ContentType = "application/vnd.ms-excel" ' set the content type
Response.AddHeader("Content-Disposition", " attachment; filename=urreportname.xls")
Dim stringWrite As New System.IO.StringWriter
Dim htmlWrite As New System.Web.UI.HtmlTextWriter(stringWrite)
Dim dg As New System.Web.UI.WebControls.DataGrid
dg.DataSource = myDataSet.Tables(0) ' it is here where u need to assign ur datatable
dg.DataBind()
dg.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString)
Response.End()
|