下载从SQL Server varbinary数据

编程入门 行业动态 更新时间:2024-10-11 23:23:15
本文介绍了下载从SQL Server varbinary数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个 VARBINARY(最大)列,基本上是一个SQL Server表COM pressed数据。

I have a SQL Server table with a Varbinary(Max) column that is basically compressed data.

我的页面,用户可以下载此数据(通常用户身份验证后)。

My page allows users to download this data (after usual user authentication).

它曾经工作确定,较小的数据大小,但现在随着时间的推移,数据也越来越大。我现在面临很多的问题基本上是一个等待时间,出现保存对话框之前。

It used to work ok, with smaller data size, but now with time, the data is also getting bigger. I am facing lot of problems basically a wait time, before the Save dialog appears.

code:

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(); }

在调试器,我可以看到,

In the debugger, I can see that

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

在这里的滞后。

我的平台是ASP.Net与.NET框架4.0,SQL Server 2008中,C#codebehind

My platform is ASP.Net with .NET Framework 4.0, SQL Server 2008, C# codebehind

推荐答案

您需要流响应返回。读取内存中的所有文件,然后写出来是不会扩展,你会开始exhasting服务器的请求数或的文件的大小增加。

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.

看一看的并的下载和上传图片-images - 从-SQL服务器/相对=nofollow> FILESTREAM MVC:从SQL Server 的下载和上传图像,看看如何做到这一点的例子。当你不使用MVC,但直ASP.NEt你可以做更简单,但想法是一样的:

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:

  • 使用一个流API来读取数据库的响应(特别是 SqlCommand.ExecuteReade 与 CommandBehavior.SequentialAccess )和读取使用的 SqlDataReader.GetBytes() (注意的重要性在MSDN上再次小文档片断 SequentialAccess 标志...)
  • 使用流API写的HTTP响应。 Response.BinaryWrite () 就行了。
  • use a streaming API to read the database response (specifically SqlCommand.ExecuteReade with CommandBehavior.SequentialAccess) and read the response in chunks, using SqlDataReader.GetBytes() (note again the small snipped on MSDN about the importance of SequentialAccess flag...)
  • use a streaming API to write the HTTP response. Response.BinaryWrite() will do.

更多推荐

下载从SQL Server varbinary数据

本文发布于:2023-11-08 06:12:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1568560.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   SQL   Server   varbinary

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!