首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将数据导出到excel时出现异常

将数据导出到excel时出现异常
EN

Stack Overflow用户
提问于 2010-12-01 13:17:41
回答 2查看 807关注 0票数 0

将数据导出到excel工作表时出现以下错误

代码语言:javascript
复制
ERROR:
Message : 
Exception of type 'System.Web.HttpUnhandledException' was thrown.
Error Description : 
System.Web.HttpUnhandledException: Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> System.Data.SqlClient.SqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

有没有人建议我该怎么做。

代码语言:javascript
复制
CODE:
gridData.dataSource = GetData()
gridData.DataBind()


Response.Clear()
Response.AddHeader("content-disposition",   "attachment;filename=CompletionDatesReport.xls")
Response.Charset = ""
Response.Cache.SetCacheability(HttpCacheability.NoCache)
Response.ContentType = "application/vnd.xls"
Dim stringWrite As StringWriter = New StringWriter()
Dim htmlWrite As HtmlTextWriter = New HtmlTextWriter(stringWrite)
gridData.RenderControl(htmlWrite)
Response.Write(stringWrite.ToString())
Response.End()
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2010-12-01 14:08:59

没有代码,我们只能猜测,但SqlException: Timeout expired中有一个很大的线索-这表明您的查询花费了太长的时间。您可以增加命令的超时时间(但要尽量保持正常...)通过SqlCommand.CommandTimeout,但编写更高效的查询,或者不在一个查询中提取那么多的数据,通常会更可取。

票数 0
EN

Stack Overflow用户

发布于 2010-12-01 14:12:58

我同意马克的观点。查看一下您的查询并对其进行优化,删除DISTINCT语句等以使其更快。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4321424

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档