Click here to Skip to main content
15,940,921 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Getting exception time out error when i export the huge data into excel sheet.

There are more than 40,000 records in my gridview.


My code is below

iam using telerik radgrid to export the radgrid data into excel.

iam getting the error message as

"Log entry string is too long. A string written to the event log cannot exceed 32766 characters."


C#
protected void exportButton_Click(object sender, System.EventArgs e)
{
 
RadGrid1.ExportSettings.OpenInNewWindow = true;
RadGrid1.ExportSettings.FileName = "AgingDetail";
RadGrid1.ExportSettings.ExportOnlyData = true;
RadGrid1.ExportSettings.OpenInNewWindow = true;
RadGrid1.ExportSettings.IgnorePaging = true;
foreach (GridFilteringItem item in RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem))
{
item.Visible = false;
}
RadGrid1.MasterTableView.GetColumn("supname").Display = true;
RadGrid1.MasterTableView.GetColumn("repname").Display = true;
RadGrid1.MasterTableView.GetColumn("centername").Display = true;
RadGrid1.MasterTableView.GetColumn("Priority").Display = false;
RadGrid1.MasterTableView.GetColumn("Cust_Num").Display = false;
RadGrid1.MasterTableView.GetColumn("Cust_Num1").Display = true;
RadGrid1.MasterTableView.GetColumn("ins_num").Display = false;
RadGrid1.MasterTableView.GetColumn("ins_num1").Display = true;
 
RadGrid1.MasterTableView.ExportToExcel();
}
Posted
Updated 9-Jun-14 19:31pm
v5

Hi raheem,
Try this may it work for you.

XML
string FileName = "StudentAttendanceReport";
            // DataTable dt = ds.Tables[0];
            Context.Response.Write("<table border=1 width='100%'><tr align = 'center'>");
            for (int i = 0; i < dt.Columns.Count; i++)
            {
                Context.Response.Write("<td><B>" + dt.Columns[i].ToString() + "</B></td>");

            }

            Context.Response.Write("</tr>");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow dr = dt.Rows[i];
                Context.Response.Write("<tr align = 'Left'>");
                for (int iCol = 0; iCol < dt.Columns.Count; iCol++)
                {
                    switch (dr[iCol].ToString())
                    {
                        case "/":
                            Context.Response.Write("<td nowrap>" + "" + "</td>");
                            break;
                        default:
                            Context.Response.Write("<td nowrap>" + dr[iCol].ToString() + "</td>");
                            break;
                    }

                }
                Context.Response.Write("</tr>");
            }
            Context.Response.Write("</table>");

            Context.Response.AddHeader("Content-Disposition", "attachment;filename=" + FileName + ".xls");
            Context.Response.ContentType = "application/vnd.ms-excel";
            Context.Response.Charset = "";
            Context.Response.Flush();
            Context.Response.Close();
            Context.Response.End();
        }
        catch (Exception)
        {

            // throw;
        }
 
Share this answer
 
Comments
Raheem Mohammad 10-Jun-14 1:06am    
hi vijay,

Your code is not working for me.

It is saying that - Unable to download the Excel sheet
Raheem Mohammad 10-Jun-14 1:08am    
My code is below

iam using telerik radgrid to export the radgrid data into excel.

iam getting the error message as

"Log entry string is too long. A string written to the event log cannot exceed 32766 characters."


protected void exportButton_Click(object sender, System.EventArgs e)
{

RadGrid1.ExportSettings.OpenInNewWindow = true;
RadGrid1.ExportSettings.FileName = "AgingDetail";
RadGrid1.ExportSettings.ExportOnlyData = true;
RadGrid1.ExportSettings.OpenInNewWindow = true;
RadGrid1.ExportSettings.IgnorePaging = true;
foreach (GridFilteringItem item in RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem))
{
item.Visible = false;
}
RadGrid1.MasterTableView.GetColumn("supname").Display = true;
RadGrid1.MasterTableView.GetColumn("repname").Display = true;
RadGrid1.MasterTableView.GetColumn("centername").Display = true;
RadGrid1.MasterTableView.GetColumn("Priority").Display = false;
RadGrid1.MasterTableView.GetColumn("Cust_Num").Display = false;
RadGrid1.MasterTableView.GetColumn("Cust_Num1").Display = true;
RadGrid1.MasterTableView.GetColumn("ins_num").Display = false;
RadGrid1.MasterTableView.GetColumn("ins_num1").Display = true;

RadGrid1.MasterTableView.ExportToExcel();
}
As there is a large amount of data for you you can increase the timeout time for your command object while fetching :-

C#
SqlCommand cmd = new SqlCommand("your query", {connection object});
cmd.CommandTimeout = 999999 ;


Hope this will work for you.
 
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