首页 新闻 会员 周边

批量转换数据性能问题(http程序超时)

0
悬赏园豆:5 [已关闭问题]

上次那问题没解决,这次贴些代码好说问题吧,web程序,功能是把数据库里某个分类的新闻都读到一个DataTable里,然后根据静态模板替换站位符号,用StreamWriter写到硬盘上。

 public void ToHtmls(string htmlTemplate,DataTable dt)
        {
            int count = dt.Rows.Count;
            for (int i = 0; i < count; i++)
            {

string filePath = GlobalConfig.NewsDetailPath + dt.Rows[i]["FileUrl"].ToString().Replace("/", "\\");
                string fullPath = filePath;
                filePath = filePath.Substring(0, filePath.LastIndexOf("\\"));
                if (!Directory.Exists(filePath))
                {
                    DirectoryInfo di = new DirectoryInfo(filePath);//如果没有文件夹则创建一个
                    di.Create();
                }
                //string fullPath = Util.PATH + dt.Rows[i]["FilePath"].ToString() + dt.Rows[i]["FileName"].ToString();

                //创建一个文件
                StreamWriter sw = new StreamWriter(fullPath, false, Encoding.UTF8);

 

//获取模版内容,并替换模版中的站位符号为具体内容
                StringBuilder sb = new StringBuilder(htmlTemplate);
                sb.Replace("{%[Category1Id]%}", dt.Rows[i]["Category1"].ToString());

//接下来都是用StringBuilder替换站位符号,就不写了。

 

 sw.Write(sb.ToString());
                sw.Flush();
                sw.Close();
                sw.Dispose();

 }

1000条新闻,在本地测试几秒就生成完了,网上执行就提示超时,config里修改了超时时间也没用

<httpRuntime executionTimeout="1000" />

红尘中迷茫的主页 红尘中迷茫 | 初学一级 | 园豆:60
提问于:2009-05-06 12:00
< >
分享
其他回答(1)
0

直接在SQL Server的查询分析器中写一句Update:

update '表名' set 更新的字段名 = replace (更新的字段名,'被替换的特定字符','替换成的字符') 

Insus.NET | 园豆:932 (小虾三级) | 2009-05-06 12:32
0

如果1000条超时,我觉得你可以尝试着做100条,然后算一下单个平均时间,确认是“慢”而不是其他错误。

Jeffrey Zhao | 园豆:1629 (小虾三级) | 2009-05-06 21:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册