0

我有一个 SQL Server 表,其中有一Varbinary(Max)列基本上是压缩数据。

我的页面允许用户下载这些数据(在通常的用户身份验证之后)。

它以前工作正常,数据量较小,但现在随着时间的推移,数据也越来越大。我面临很多问题,基本上是等待时间,在“保存”对话框出现之前。

代码:

 while (reader.Read())
            {
                Response.Buffer = false;
                Response.Charset = "";
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                Response.ContentType = "application/gzip";
                Response.AddHeader("content-disposition", "attachment;filename="
                + "vbet_1_1.sdf.gz");
                byte[] bytes = (Byte[])reader["backupdata"]; // STUCK HERE
                Response.BinaryWrite(bytes);
                Response.Flush();
                Response.End();
            }

在调试器中,我可以看到

byte[] bytes = (Byte[])reader["backupdata"];

是滞后的地方。

我的平台是带有 .NET Framework 4.0、SQL Server 2008、C# 代码隐藏的 ASP.Net

4

2 回答 2

1

You need to stream the response back. Reading the entire file in memory and then writing it out is not going to scale and you'll start exhasting the server as the number of requests or the size of the files increase.

Have a look at Download and Upload images from SQL Server via ASP.Net MVC and FILESTREAM MVC: Download and Upload images from SQL Server to see an example of how to do this. As you do not use MVC but straight ASP.NEt you can do it simpler, but the ideas are the same:

于 2013-10-22T11:35:40.213 回答
1

这可能会有所帮助:

Response.AppendHeader("Content-Type", "application/gzip ");
Response.OutputStream.Write((Byte[])reader["backupdata"],0,((Byte[])reader["backupdata"]).Length); 

并且可以使用 sql2012 的文件流表直接存储文件

于 2013-10-22T13:15:58.507 回答