473,735 Members | 2,799 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

streaming binary data from sql 2005

Hi all, is there a better way to stream binary data stored in a table in sql
2005 to a browser in .net 2.0? Or is the code same as in .net 1.1? We
noticed that in certain heavy load scenarios, every now and then the client
would timeout and have to re-initiate the request...

TIA!
Nov 23 '05 #1
6 2726
the technique is the same. you will gain a performance boost if you switch
to a varbinary(max) column over image. there are improvements in
transferring the data.

note: using asp.net for downloads is problematic. asp.net has a limited
number of request threads and a limited number of connection from the
asp.net worker process to .net isapi filter. this means you can not support
a lot of simultaneous downloads. even though its heavy on resources, you
might fiond buffering the download is best. this fress up the asp.net worker
thread quicker.
-- bruce (sqlwork.com)
<pa***@communit y.nospam> wrote in message
news:un******** ******@TK2MSFTN GP15.phx.gbl...
Hi all, is there a better way to stream binary data stored in a table in
sql 2005 to a browser in .net 2.0? Or is the code same as in .net 1.1? We
noticed that in certain heavy load scenarios, every now and then the
client would timeout and have to re-initiate the request...

TIA!

Nov 23 '05 #2
Hi, could you please shed some light on "buffering the download" ? Here is
my code right now. I call the dbchunks2stream method which essentially
chunks the data to response.output stream

Public Sub WriteChunks2DB( tablename as string, columnname as string,
pkcolumnname as string, pkcolumnval as string, s as stream)
Dim BUFFER_LENGTH As Integer = 131072 ' chunk size

' Make sure that Photo is non-NULL and return TEXTPTR to it.
Dim sqlstr as string = "SET NOCOUNT ON;UPDATE " + tablename + " SET " +
columnname + " = 0x0 WHERE " + pkcolumnname + "= '" +
replacequotes(p kcolumnval) + "';SELECT @Pointer=TEXTPT R(" + columnname + ")
FROM " + tablename + " WHERE " + pkcolumnname + " = '" +
replacequotes(p kcolumnval) + "'"
Dim cmdGetPointer As New SqlCommand(sqls tr, objConnect)
Dim PointerOutParam As SqlParameter =
cmdGetPointer.P arameters.Add(" @Pointer", SqlDbType.VarBi nary, 100)
PointerOutParam .Direction = ParameterDirect ion.Output
if objConnect.stat e = ConnectionState .Closed Then objConnect.Open

cmdGetPointer.E xecuteNonQuery( )

' Set up UPDATETEXT command, parameters, and open BinaryReader.
sqlstr = "UPDATETEXT " + tablename + "." + columnname + " @Pointer
@Offset @Delete WITH LOG @Bytes"
Dim cmdUploadBinary As New SqlCommand(sqls tr, objConnect)
Dim PointerParam As SqlParameter =
cmdUploadBinary .Parameters.Add ("@Pointer", SqlDbType.Binar y, 16)
Dim OffsetParam As SqlParameter =
cmdUploadBinary .Parameters.Add ("@Offset", SqlDbType.Int)
Dim DeleteParam As SqlParameter =
cmdUploadBinary .Parameters.Add ("@Delete", SqlDbType.Int)
DeleteParam.Val ue = 1 ' delete 0x0 character
Dim BytesParam As SqlParameter =
cmdUploadBinary .Parameters.Add ("@Bytes", SqlDbType.Binar y, BUFFER_LENGTH)
Dim br As New BinaryReader(s)
Dim Offset As Integer = 0
OffsetParam.Val ue = Offset

' Read buffer full of data and execute the UPDATETEXT statement.
Dim Buffer() As Byte = br.ReadBytes(BU FFER_LENGTH)
Do While Buffer.Length > 0
PointerParam.Va lue = PointerOutParam .Value
BytesParam.Valu e = Buffer
cmdUploadBinary .ExecuteNonQuer y()
DeleteParam.Val ue = 0 ' don't delete any other data
Offset += Buffer.Length
OffsetParam.Val ue = Offset
Buffer = br.ReadBytes(BU FFER_LENGTH)
Loop

br.Close()
s.Close()
objConnect.Clos e()

End Sub

Public Sub DBChunks2Stream (tablename as string, columnname as string,
pkcolumnname as string, pkcolumnval as string, byref s as stream)
Dim ImageCol As Integer = 0 ' position of image column in DataReader
Dim BUFFER_LENGTH As Integer = 131072 ' chunk size

' Make sure that Photo is non-NULL and return TEXTPTR to it.
Dim sqlstr as string = "SELECT @Pointer=TEXTPT R(" + columnname + "),
@Length=DataLen gth(" + columnname + ") FROM " + tablename + " WHERE " +
pkcolumnname + " = '" + pkcolumnval + "'"
Dim cmdGetPointer As New SqlCommand(sqls tr, objConnect)
Dim PointerOutParam As SqlParameter =
cmdGetPointer.P arameters.Add(" @Pointer", SqlDbType.VarBi nary, 100)
PointerOutParam .Direction = ParameterDirect ion.Output
Dim LengthOutParam As SqlParameter =
cmdGetPointer.P arameters.Add(" @Length", SqlDbType.Int)
LengthOutParam. Direction = ParameterDirect ion.Output
if objConnect.stat e = ConnectionState .Closed Then objConnect.Open
cmdGetPointer.E xecuteNonQuery( )
If PointerOutParam .Value Is DBNull.Value Then
objConnect.Clos e()
' Add code to deal with NULL BLOB.
Exit Sub
End If

' Set up READTEXT command, parameters, and open BinaryReader.
sqlstr = "READTEXT " + tablename + "." + columnname + " @Pointer @Offset
@Size HOLDLOCK"
Dim cmdReadBinary As New SqlCommand(sqls tr, objConnect)
Dim PointerParam As SqlParameter =
cmdReadBinary.P arameters.Add(" @Pointer", SqlDbType.Binar y, 16)
Dim OffsetParam As SqlParameter =
cmdReadBinary.P arameters.Add(" @Offset", SqlDbType.Int)
Dim SizeParam As SqlParameter = cmdReadBinary.P arameters.Add(" @Size",
SqlDbType.Int)
Dim dr As SqlDataReader
Dim Offset As Integer = 0
OffsetParam.Val ue = Offset
Dim Buffer(BUFFER_L ENGTH - 1) As Byte

' Read buffer full of data and write to the file stream.
Do
PointerParam.Va lue = PointerOutParam .Value
' Calculate the buffer size - may be less than BUFFER_LENGTH for the
last block.
If Offset + BUFFER_LENGTH >= Cint(LengthOutP aram.Value) Then
SizeParam.Value = Ctype((Cint(Len gthOutParam.Val ue) - Offset),
Object)
Else
SizeParam.Value = Ctype(BUFFER_LE NGTH, Object)
End If
dr = cmdReadBinary.E xecuteReader(Co mmandBehavior.S ingleResult)
dr.Read()
dr.GetBytes(Ima geCol, 0, Buffer, 0, Cint(SizeParam. Value))
dr.Close()
s.Write(Buffer, 0, Cint(SizeParam. Value))
Offset += Cint(SizeParam. Value)
OffsetParam.Val ue = Ctype(Offset, Object)
Loop Until Offset >= Cint(LengthOutP aram.Value)

s.Close()
objConnect.Clos e()

End Sub

TIA!
"Bruce Barker" <br************ ******@safeco.c om> wrote in message
news:el******** ******@TK2MSFTN GP14.phx.gbl...
the technique is the same. you will gain a performance boost if you switch
to a varbinary(max) column over image. there are improvements in
transferring the data.

note: using asp.net for downloads is problematic. asp.net has a limited
number of request threads and a limited number of connection from the
asp.net worker process to .net isapi filter. this means you can not
support a lot of simultaneous downloads. even though its heavy on
resources, you might fiond buffering the download is best. this fress up
the asp.net worker thread quicker.
-- bruce (sqlwork.com)
<pa***@communit y.nospam> wrote in message
news:un******** ******@TK2MSFTN GP15.phx.gbl...
Hi all, is there a better way to stream binary data stored in a table in
sql 2005 to a browser in .net 2.0? Or is the code same as in .net 1.1? We
noticed that in certain heavy load scenarios, every now and then the
client would timeout and have to re-initiate the request...

TIA!


Nov 24 '05 #3
Hi Param,

I think the Buffering Bruce mentioned means the OutputBuffer setting for
asp.net web page. We can set it in the @Page directive like:

<%@Page ..... Buffer="true". .... %>

or in code through:

Page_load(...)
{
Response.Buffer Output = true;
}

The default should be ture. Setting Buffer can help us buffer the response
data at serversdie so as to flush them once all the data is complete.
However, this will cause the server memory be comsumed seriously when lots
of request executing for large data downloading.... .

Also, I think it'll be better to implement file download in raw IIS isapi
filter or extension and seems .NET 2.0 support developing IIS isapi
components through managed code..

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: <pa***@communit y.nospam>
| References: <un************ **@TK2MSFTNGP15 .phx.gbl>
<el************ **@TK2MSFTNGP14 .phx.gbl>
| Subject: Re: streaming binary data from sql 2005
| Date: Wed, 23 Nov 2005 20:19:04 -0600
| Lines: 156
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-RFC2646: Format=Flowed; Response
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| Message-ID: <Ov************ *@TK2MSFTNGP09. phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: corp2.lazardgro up.com 70.182.148.88
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3606 09
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Hi, could you please shed some light on "buffering the download" ? Here
is
| my code right now. I call the dbchunks2stream method which essentially
| chunks the data to response.output stream
|
| Public Sub WriteChunks2DB( tablename as string, columnname as string,
| pkcolumnname as string, pkcolumnval as string, s as stream)
| Dim BUFFER_LENGTH As Integer = 131072 ' chunk size
|
| ' Make sure that Photo is non-NULL and return TEXTPTR to it.
| Dim sqlstr as string = "SET NOCOUNT ON;UPDATE " + tablename + " SET "
+
| columnname + " = 0x0 WHERE " + pkcolumnname + "= '" +
| replacequotes(p kcolumnval) + "';SELECT @Pointer=TEXTPT R(" + columnname +
")
| FROM " + tablename + " WHERE " + pkcolumnname + " = '" +
| replacequotes(p kcolumnval) + "'"
| Dim cmdGetPointer As New SqlCommand(sqls tr, objConnect)
| Dim PointerOutParam As SqlParameter =
| cmdGetPointer.P arameters.Add(" @Pointer", SqlDbType.VarBi nary, 100)
| PointerOutParam .Direction = ParameterDirect ion.Output
| if objConnect.stat e = ConnectionState .Closed Then objConnect.Open
|
| cmdGetPointer.E xecuteNonQuery( )
|
| ' Set up UPDATETEXT command, parameters, and open BinaryReader.
| sqlstr = "UPDATETEXT " + tablename + "." + columnname + " @Pointer
| @Offset @Delete WITH LOG @Bytes"
| Dim cmdUploadBinary As New SqlCommand(sqls tr, objConnect)
| Dim PointerParam As SqlParameter =
| cmdUploadBinary .Parameters.Add ("@Pointer", SqlDbType.Binar y, 16)
| Dim OffsetParam As SqlParameter =
| cmdUploadBinary .Parameters.Add ("@Offset", SqlDbType.Int)
| Dim DeleteParam As SqlParameter =
| cmdUploadBinary .Parameters.Add ("@Delete", SqlDbType.Int)
| DeleteParam.Val ue = 1 ' delete 0x0 character
| Dim BytesParam As SqlParameter =
| cmdUploadBinary .Parameters.Add ("@Bytes", SqlDbType.Binar y, BUFFER_LENGTH)
| Dim br As New BinaryReader(s)
| Dim Offset As Integer = 0
| OffsetParam.Val ue = Offset
|
| ' Read buffer full of data and execute the UPDATETEXT statement.
| Dim Buffer() As Byte = br.ReadBytes(BU FFER_LENGTH)
| Do While Buffer.Length > 0
| PointerParam.Va lue = PointerOutParam .Value
| BytesParam.Valu e = Buffer
| cmdUploadBinary .ExecuteNonQuer y()
| DeleteParam.Val ue = 0 ' don't delete any other data
| Offset += Buffer.Length
| OffsetParam.Val ue = Offset
| Buffer = br.ReadBytes(BU FFER_LENGTH)
| Loop
|
| br.Close()
| s.Close()
| objConnect.Clos e()
|
| End Sub
|
| Public Sub DBChunks2Stream (tablename as string, columnname as string,
| pkcolumnname as string, pkcolumnval as string, byref s as stream)
| Dim ImageCol As Integer = 0 ' position of image column in DataReader
| Dim BUFFER_LENGTH As Integer = 131072 ' chunk size
|
| ' Make sure that Photo is non-NULL and return TEXTPTR to it.
| Dim sqlstr as string = "SELECT @Pointer=TEXTPT R(" + columnname + "),
| @Length=DataLen gth(" + columnname + ") FROM " + tablename + " WHERE " +
| pkcolumnname + " = '" + pkcolumnval + "'"
| Dim cmdGetPointer As New SqlCommand(sqls tr, objConnect)
| Dim PointerOutParam As SqlParameter =
| cmdGetPointer.P arameters.Add(" @Pointer", SqlDbType.VarBi nary, 100)
| PointerOutParam .Direction = ParameterDirect ion.Output
| Dim LengthOutParam As SqlParameter =
| cmdGetPointer.P arameters.Add(" @Length", SqlDbType.Int)
| LengthOutParam. Direction = ParameterDirect ion.Output
| if objConnect.stat e = ConnectionState .Closed Then objConnect.Open
| cmdGetPointer.E xecuteNonQuery( )
| If PointerOutParam .Value Is DBNull.Value Then
| objConnect.Clos e()
| ' Add code to deal with NULL BLOB.
| Exit Sub
| End If
|
| ' Set up READTEXT command, parameters, and open BinaryReader.
| sqlstr = "READTEXT " + tablename + "." + columnname + " @Pointer
@Offset
| @Size HOLDLOCK"
| Dim cmdReadBinary As New SqlCommand(sqls tr, objConnect)
| Dim PointerParam As SqlParameter =
| cmdReadBinary.P arameters.Add(" @Pointer", SqlDbType.Binar y, 16)
| Dim OffsetParam As SqlParameter =
| cmdReadBinary.P arameters.Add(" @Offset", SqlDbType.Int)
| Dim SizeParam As SqlParameter = cmdReadBinary.P arameters.Add(" @Size",
| SqlDbType.Int)
| Dim dr As SqlDataReader
| Dim Offset As Integer = 0
| OffsetParam.Val ue = Offset
| Dim Buffer(BUFFER_L ENGTH - 1) As Byte
|
| ' Read buffer full of data and write to the file stream.
| Do
| PointerParam.Va lue = PointerOutParam .Value
| ' Calculate the buffer size - may be less than BUFFER_LENGTH for
the
| last block.
| If Offset + BUFFER_LENGTH >= Cint(LengthOutP aram.Value) Then
| SizeParam.Value = Ctype((Cint(Len gthOutParam.Val ue) - Offset),
| Object)
| Else
| SizeParam.Value = Ctype(BUFFER_LE NGTH, Object)
| End If
| dr = cmdReadBinary.E xecuteReader(Co mmandBehavior.S ingleResult)
| dr.Read()
| dr.GetBytes(Ima geCol, 0, Buffer, 0, Cint(SizeParam. Value))
| dr.Close()
| s.Write(Buffer, 0, Cint(SizeParam. Value))
| Offset += Cint(SizeParam. Value)
| OffsetParam.Val ue = Ctype(Offset, Object)
| Loop Until Offset >= Cint(LengthOutP aram.Value)
|
| s.Close()
| objConnect.Clos e()
|
| End Sub
|
|
|
| TIA!
|
|
| "Bruce Barker" <br************ ******@safeco.c om> wrote in message
| news:el******** ******@TK2MSFTN GP14.phx.gbl...
| > the technique is the same. you will gain a performance boost if you
switch
| > to a varbinary(max) column over image. there are improvements in
| > transferring the data.
| >
| > note: using asp.net for downloads is problematic. asp.net has a limited
| > number of request threads and a limited number of connection from the
| > asp.net worker process to .net isapi filter. this means you can not
| > support a lot of simultaneous downloads. even though its heavy on
| > resources, you might fiond buffering the download is best. this fress
up
| > the asp.net worker thread quicker.
| >
| >
| > -- bruce (sqlwork.com)
| >
| >
| > <pa***@communit y.nospam> wrote in message
| > news:un******** ******@TK2MSFTN GP15.phx.gbl...
| >> Hi all, is there a better way to stream binary data stored in a table
in
| >> sql 2005 to a browser in .net 2.0? Or is the code same as in .net 1.1?
We
| >> noticed that in certain heavy load scenarios, every now and then the
| >> client would timeout and have to re-initiate the request...
| >>
| >> TIA!
| >>
| >
| >
|
|
|

Nov 24 '05 #4
Steve, do you have some links to some samples on how to develop an isapi
filter in .net 2.0? I have never attempted that before and dont know where
to begin. We are working on a large app where pdf files have to be securely
stored in a sql database & streamed down to users in their browser. We are
expecting upto 10,000+ simultaneous users at any given time.

TIA!

"Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
news:06******** ******@TK2MSFTN GXA02.phx.gbl.. .
Hi Param,

I think the Buffering Bruce mentioned means the OutputBuffer setting for
asp.net web page. We can set it in the @Page directive like:

<%@Page ..... Buffer="true". .... %>

or in code through:

Page_load(...)
{
Response.Buffer Output = true;
}

The default should be ture. Setting Buffer can help us buffer the response
data at serversdie so as to flush them once all the data is complete.
However, this will cause the server memory be comsumed seriously when lots
of request executing for large data downloading.... .

Also, I think it'll be better to implement file download in raw IIS isapi
filter or extension and seems .NET 2.0 support developing IIS isapi
components through managed code..

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| From: <pa***@communit y.nospam>
| References: <un************ **@TK2MSFTNGP15 .phx.gbl>
<el************ **@TK2MSFTNGP14 .phx.gbl>
| Subject: Re: streaming binary data from sql 2005
| Date: Wed, 23 Nov 2005 20:19:04 -0600
| Lines: 156
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-RFC2646: Format=Flowed; Response
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| Message-ID: <Ov************ *@TK2MSFTNGP09. phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: corp2.lazardgro up.com 70.182.148.88
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3606 09
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Hi, could you please shed some light on "buffering the download" ? Here
is
| my code right now. I call the dbchunks2stream method which essentially
| chunks the data to response.output stream
|
| Public Sub WriteChunks2DB( tablename as string, columnname as string,
| pkcolumnname as string, pkcolumnval as string, s as stream)
| Dim BUFFER_LENGTH As Integer = 131072 ' chunk size
|
| ' Make sure that Photo is non-NULL and return TEXTPTR to it.
| Dim sqlstr as string = "SET NOCOUNT ON;UPDATE " + tablename + " SET
"
+
| columnname + " = 0x0 WHERE " + pkcolumnname + "= '" +
| replacequotes(p kcolumnval) + "';SELECT @Pointer=TEXTPT R(" + columnname +
")
| FROM " + tablename + " WHERE " + pkcolumnname + " = '" +
| replacequotes(p kcolumnval) + "'"
| Dim cmdGetPointer As New SqlCommand(sqls tr, objConnect)
| Dim PointerOutParam As SqlParameter =
| cmdGetPointer.P arameters.Add(" @Pointer", SqlDbType.VarBi nary, 100)
| PointerOutParam .Direction = ParameterDirect ion.Output
| if objConnect.stat e = ConnectionState .Closed Then objConnect.Open
|
| cmdGetPointer.E xecuteNonQuery( )
|
| ' Set up UPDATETEXT command, parameters, and open BinaryReader.
| sqlstr = "UPDATETEXT " + tablename + "." + columnname + " @Pointer
| @Offset @Delete WITH LOG @Bytes"
| Dim cmdUploadBinary As New SqlCommand(sqls tr, objConnect)
| Dim PointerParam As SqlParameter =
| cmdUploadBinary .Parameters.Add ("@Pointer", SqlDbType.Binar y, 16)
| Dim OffsetParam As SqlParameter =
| cmdUploadBinary .Parameters.Add ("@Offset", SqlDbType.Int)
| Dim DeleteParam As SqlParameter =
| cmdUploadBinary .Parameters.Add ("@Delete", SqlDbType.Int)
| DeleteParam.Val ue = 1 ' delete 0x0 character
| Dim BytesParam As SqlParameter =
| cmdUploadBinary .Parameters.Add ("@Bytes", SqlDbType.Binar y,
BUFFER_LENGTH)
| Dim br As New BinaryReader(s)
| Dim Offset As Integer = 0
| OffsetParam.Val ue = Offset
|
| ' Read buffer full of data and execute the UPDATETEXT statement.
| Dim Buffer() As Byte = br.ReadBytes(BU FFER_LENGTH)
| Do While Buffer.Length > 0
| PointerParam.Va lue = PointerOutParam .Value
| BytesParam.Valu e = Buffer
| cmdUploadBinary .ExecuteNonQuer y()
| DeleteParam.Val ue = 0 ' don't delete any other data
| Offset += Buffer.Length
| OffsetParam.Val ue = Offset
| Buffer = br.ReadBytes(BU FFER_LENGTH)
| Loop
|
| br.Close()
| s.Close()
| objConnect.Clos e()
|
| End Sub
|
| Public Sub DBChunks2Stream (tablename as string, columnname as string,
| pkcolumnname as string, pkcolumnval as string, byref s as stream)
| Dim ImageCol As Integer = 0 ' position of image column in DataReader
| Dim BUFFER_LENGTH As Integer = 131072 ' chunk size
|
| ' Make sure that Photo is non-NULL and return TEXTPTR to it.
| Dim sqlstr as string = "SELECT @Pointer=TEXTPT R(" + columnname + "),
| @Length=DataLen gth(" + columnname + ") FROM " + tablename + " WHERE " +
| pkcolumnname + " = '" + pkcolumnval + "'"
| Dim cmdGetPointer As New SqlCommand(sqls tr, objConnect)
| Dim PointerOutParam As SqlParameter =
| cmdGetPointer.P arameters.Add(" @Pointer", SqlDbType.VarBi nary, 100)
| PointerOutParam .Direction = ParameterDirect ion.Output
| Dim LengthOutParam As SqlParameter =
| cmdGetPointer.P arameters.Add(" @Length", SqlDbType.Int)
| LengthOutParam. Direction = ParameterDirect ion.Output
| if objConnect.stat e = ConnectionState .Closed Then objConnect.Open
| cmdGetPointer.E xecuteNonQuery( )
| If PointerOutParam .Value Is DBNull.Value Then
| objConnect.Clos e()
| ' Add code to deal with NULL BLOB.
| Exit Sub
| End If
|
| ' Set up READTEXT command, parameters, and open BinaryReader.
| sqlstr = "READTEXT " + tablename + "." + columnname + " @Pointer
@Offset
| @Size HOLDLOCK"
| Dim cmdReadBinary As New SqlCommand(sqls tr, objConnect)
| Dim PointerParam As SqlParameter =
| cmdReadBinary.P arameters.Add(" @Pointer", SqlDbType.Binar y, 16)
| Dim OffsetParam As SqlParameter =
| cmdReadBinary.P arameters.Add(" @Offset", SqlDbType.Int)
| Dim SizeParam As SqlParameter =
cmdReadBinary.P arameters.Add(" @Size",
| SqlDbType.Int)
| Dim dr As SqlDataReader
| Dim Offset As Integer = 0
| OffsetParam.Val ue = Offset
| Dim Buffer(BUFFER_L ENGTH - 1) As Byte
|
| ' Read buffer full of data and write to the file stream.
| Do
| PointerParam.Va lue = PointerOutParam .Value
| ' Calculate the buffer size - may be less than BUFFER_LENGTH for
the
| last block.
| If Offset + BUFFER_LENGTH >= Cint(LengthOutP aram.Value) Then
| SizeParam.Value = Ctype((Cint(Len gthOutParam.Val ue) - Offset),
| Object)
| Else
| SizeParam.Value = Ctype(BUFFER_LE NGTH, Object)
| End If
| dr = cmdReadBinary.E xecuteReader(Co mmandBehavior.S ingleResult)
| dr.Read()
| dr.GetBytes(Ima geCol, 0, Buffer, 0, Cint(SizeParam. Value))
| dr.Close()
| s.Write(Buffer, 0, Cint(SizeParam. Value))
| Offset += Cint(SizeParam. Value)
| OffsetParam.Val ue = Ctype(Offset, Object)
| Loop Until Offset >= Cint(LengthOutP aram.Value)
|
| s.Close()
| objConnect.Clos e()
|
| End Sub
|
|
|
| TIA!
|
|
| "Bruce Barker" <br************ ******@safeco.c om> wrote in message
| news:el******** ******@TK2MSFTN GP14.phx.gbl...
| > the technique is the same. you will gain a performance boost if you
switch
| > to a varbinary(max) column over image. there are improvements in
| > transferring the data.
| >
| > note: using asp.net for downloads is problematic. asp.net has a
limited
| > number of request threads and a limited number of connection from the
| > asp.net worker process to .net isapi filter. this means you can not
| > support a lot of simultaneous downloads. even though its heavy on
| > resources, you might fiond buffering the download is best. this fress
up
| > the asp.net worker thread quicker.
| >
| >
| > -- bruce (sqlwork.com)
| >
| >
| > <pa***@communit y.nospam> wrote in message
| > news:un******** ******@TK2MSFTN GP15.phx.gbl...
| >> Hi all, is there a better way to stream binary data stored in a table
in
| >> sql 2005 to a browser in .net 2.0? Or is the code same as in .net
1.1?
We
| >> noticed that in certain heavy load scenarios, every now and then the
| >> client would timeout and have to re-initiate the request...
| >>
| >> TIA!
| >>
| >
| >
|
|
|

Nov 24 '05 #5

Thanks for your response Param,

Regarding on developing IIS components through managed code in .net 2.0,
seems there hasn't detailed public reference. I'll contact some other IIS
experts to see whether they have any information on this. Also, for
developing raw ISAPI extension or filters, here're some reference:
#Taking the SplashDiving into ISAPI Programming
http://www.microsoft.com/mind/0197/isapi.asp

#ISAPI Extensions: Creating a DLL to Enable HTTP-based File Uploads with IIS
http://msdn.microsoft.com/msdnmag/is...d/default.aspx

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| From: <pa***@communit y.nospam>
| References: <un************ **@TK2MSFTNGP15 .phx.gbl>
<el************ **@TK2MSFTNGP14 .phx.gbl>
<Ov************ *@TK2MSFTNGP09. phx.gbl>
<06************ **@TK2MSFTNGXA0 2.phx.gbl>
| Subject: Re: streaming binary data from sql 2005
| Date: Thu, 24 Nov 2005 08:24:43 -0600
| Lines: 238
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| Message-ID: <O3************ **@TK2MSFTNGP14 .phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: corp2.lazardgro up.com 70.182.148.88
| Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP14.phx. gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3607 30
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Steve, do you have some links to some samples on how to develop an isapi
| filter in .net 2.0? I have never attempted that before and dont know
where
| to begin. We are working on a large app where pdf files have to be
securely
| stored in a sql database & streamed down to users in their browser. We
are
| expecting upto 10,000+ simultaneous users at any given time.
|
| TIA!
|
| "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| news:06******** ******@TK2MSFTN GXA02.phx.gbl.. .
| > Hi Param,
| >
| > I think the Buffering Bruce mentioned means the OutputBuffer setting for
| > asp.net web page. We can set it in the @Page directive like:
| >
| > <%@Page ..... Buffer="true". .... %>
| >
| > or in code through:
| >
| > Page_load(...)
| > {
| > Response.Buffer Output = true;
| > }
| >
| > The default should be ture. Setting Buffer can help us buffer the
response
| > data at serversdie so as to flush them once all the data is complete.
| > However, this will cause the server memory be comsumed seriously when
lots
| > of request executing for large data downloading.... .
| >
| > Also, I think it'll be better to implement file download in raw IIS
isapi
| > filter or extension and seems .NET 2.0 support developing IIS isapi
| > components through managed code..
| >
| > Thanks,
| >
| > Steven Cheng
| > Microsoft Online Support
| >
| > Get Secure! www.microsoft.com/security
| > (This posting is provided "AS IS", with no warranties, and confers no
| > rights.)
| >
| >
| >
| > --------------------
| > | From: <pa***@communit y.nospam>
| > | References: <un************ **@TK2MSFTNGP15 .phx.gbl>
| > <el************ **@TK2MSFTNGP14 .phx.gbl>
| > | Subject: Re: streaming binary data from sql 2005
| > | Date: Wed, 23 Nov 2005 20:19:04 -0600
| > | Lines: 156
| > | X-Priority: 3
| > | X-MSMail-Priority: Normal
| > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| > | X-RFC2646: Format=Flowed; Response
| > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| > | Message-ID: <Ov************ *@TK2MSFTNGP09. phx.gbl>
| > | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| > | NNTP-Posting-Host: corp2.lazardgro up.com 70.182.148.88
| > | Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| > | Xref: TK2MSFTNGXA02.p hx.gbl
| > microsoft.publi c.dotnet.framew ork.aspnet:3606 09
| > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| > |
| > | Hi, could you please shed some light on "buffering the download" ?
Here
| > is
| > | my code right now. I call the dbchunks2stream method which essentially
| > | chunks the data to response.output stream
| > |
| > | Public Sub WriteChunks2DB( tablename as string, columnname as string,
| > | pkcolumnname as string, pkcolumnval as string, s as stream)
| > | Dim BUFFER_LENGTH As Integer = 131072 ' chunk size
| > |
| > | ' Make sure that Photo is non-NULL and return TEXTPTR to it.
| > | Dim sqlstr as string = "SET NOCOUNT ON;UPDATE " + tablename + "
SET
| > "
| > +
| > | columnname + " = 0x0 WHERE " + pkcolumnname + "= '" +
| > | replacequotes(p kcolumnval) + "';SELECT @Pointer=TEXTPT R(" +
columnname +
| > ")
| > | FROM " + tablename + " WHERE " + pkcolumnname + " = '" +
| > | replacequotes(p kcolumnval) + "'"
| > | Dim cmdGetPointer As New SqlCommand(sqls tr, objConnect)
| > | Dim PointerOutParam As SqlParameter =
| > | cmdGetPointer.P arameters.Add(" @Pointer", SqlDbType.VarBi nary, 100)
| > | PointerOutParam .Direction = ParameterDirect ion.Output
| > | if objConnect.stat e = ConnectionState .Closed Then objConnect.Open
| > |
| > | cmdGetPointer.E xecuteNonQuery( )
| > |
| > | ' Set up UPDATETEXT command, parameters, and open BinaryReader.
| > | sqlstr = "UPDATETEXT " + tablename + "." + columnname + " @Pointer
| > | @Offset @Delete WITH LOG @Bytes"
| > | Dim cmdUploadBinary As New SqlCommand(sqls tr, objConnect)
| > | Dim PointerParam As SqlParameter =
| > | cmdUploadBinary .Parameters.Add ("@Pointer", SqlDbType.Binar y, 16)
| > | Dim OffsetParam As SqlParameter =
| > | cmdUploadBinary .Parameters.Add ("@Offset", SqlDbType.Int)
| > | Dim DeleteParam As SqlParameter =
| > | cmdUploadBinary .Parameters.Add ("@Delete", SqlDbType.Int)
| > | DeleteParam.Val ue = 1 ' delete 0x0 character
| > | Dim BytesParam As SqlParameter =
| > | cmdUploadBinary .Parameters.Add ("@Bytes", SqlDbType.Binar y,
| > BUFFER_LENGTH)
| > | Dim br As New BinaryReader(s)
| > | Dim Offset As Integer = 0
| > | OffsetParam.Val ue = Offset
| > |
| > | ' Read buffer full of data and execute the UPDATETEXT statement.
| > | Dim Buffer() As Byte = br.ReadBytes(BU FFER_LENGTH)
| > | Do While Buffer.Length > 0
| > | PointerParam.Va lue = PointerOutParam .Value
| > | BytesParam.Valu e = Buffer
| > | cmdUploadBinary .ExecuteNonQuer y()
| > | DeleteParam.Val ue = 0 ' don't delete any other data
| > | Offset += Buffer.Length
| > | OffsetParam.Val ue = Offset
| > | Buffer = br.ReadBytes(BU FFER_LENGTH)
| > | Loop
| > |
| > | br.Close()
| > | s.Close()
| > | objConnect.Clos e()
| > |
| > | End Sub
| > |
| > | Public Sub DBChunks2Stream (tablename as string, columnname as string,
| > | pkcolumnname as string, pkcolumnval as string, byref s as stream)
| > | Dim ImageCol As Integer = 0 ' position of image column in
DataReader
| > | Dim BUFFER_LENGTH As Integer = 131072 ' chunk size
| > |
| > | ' Make sure that Photo is non-NULL and return TEXTPTR to it.
| > | Dim sqlstr as string = "SELECT @Pointer=TEXTPT R(" + columnname +
"),
| > | @Length=DataLen gth(" + columnname + ") FROM " + tablename + " WHERE "
+
| > | pkcolumnname + " = '" + pkcolumnval + "'"
| > | Dim cmdGetPointer As New SqlCommand(sqls tr, objConnect)
| > | Dim PointerOutParam As SqlParameter =
| > | cmdGetPointer.P arameters.Add(" @Pointer", SqlDbType.VarBi nary, 100)
| > | PointerOutParam .Direction = ParameterDirect ion.Output
| > | Dim LengthOutParam As SqlParameter =
| > | cmdGetPointer.P arameters.Add(" @Length", SqlDbType.Int)
| > | LengthOutParam. Direction = ParameterDirect ion.Output
| > | if objConnect.stat e = ConnectionState .Closed Then objConnect.Open
| > | cmdGetPointer.E xecuteNonQuery( )
| > | If PointerOutParam .Value Is DBNull.Value Then
| > | objConnect.Clos e()
| > | ' Add code to deal with NULL BLOB.
| > | Exit Sub
| > | End If
| > |
| > | ' Set up READTEXT command, parameters, and open BinaryReader.
| > | sqlstr = "READTEXT " + tablename + "." + columnname + " @Pointer
| > @Offset
| > | @Size HOLDLOCK"
| > | Dim cmdReadBinary As New SqlCommand(sqls tr, objConnect)
| > | Dim PointerParam As SqlParameter =
| > | cmdReadBinary.P arameters.Add(" @Pointer", SqlDbType.Binar y, 16)
| > | Dim OffsetParam As SqlParameter =
| > | cmdReadBinary.P arameters.Add(" @Offset", SqlDbType.Int)
| > | Dim SizeParam As SqlParameter =
| > cmdReadBinary.P arameters.Add(" @Size",
| > | SqlDbType.Int)
| > | Dim dr As SqlDataReader
| > | Dim Offset As Integer = 0
| > | OffsetParam.Val ue = Offset
| > | Dim Buffer(BUFFER_L ENGTH - 1) As Byte
| > |
| > | ' Read buffer full of data and write to the file stream.
| > | Do
| > | PointerParam.Va lue = PointerOutParam .Value
| > | ' Calculate the buffer size - may be less than BUFFER_LENGTH
for
| > the
| > | last block.
| > | If Offset + BUFFER_LENGTH >= Cint(LengthOutP aram.Value) Then
| > | SizeParam.Value = Ctype((Cint(Len gthOutParam.Val ue) -
Offset),
| > | Object)
| > | Else
| > | SizeParam.Value = Ctype(BUFFER_LE NGTH, Object)
| > | End If
| > | dr = cmdReadBinary.E xecuteReader(Co mmandBehavior.S ingleResult)
| > | dr.Read()
| > | dr.GetBytes(Ima geCol, 0, Buffer, 0, Cint(SizeParam. Value))
| > | dr.Close()
| > | s.Write(Buffer, 0, Cint(SizeParam. Value))
| > | Offset += Cint(SizeParam. Value)
| > | OffsetParam.Val ue = Ctype(Offset, Object)
| > | Loop Until Offset >= Cint(LengthOutP aram.Value)
| > |
| > | s.Close()
| > | objConnect.Clos e()
| > |
| > | End Sub
| > |
| > |
| > |
| > | TIA!
| > |
| > |
| > | "Bruce Barker" <br************ ******@safeco.c om> wrote in message
| > | news:el******** ******@TK2MSFTN GP14.phx.gbl...
| > | > the technique is the same. you will gain a performance boost if you
| > switch
| > | > to a varbinary(max) column over image. there are improvements in
| > | > transferring the data.
| > | >
| > | > note: using asp.net for downloads is problematic. asp.net has a
| > limited
| > | > number of request threads and a limited number of connection from
the
| > | > asp.net worker process to .net isapi filter. this means you can not
| > | > support a lot of simultaneous downloads. even though its heavy on
| > | > resources, you might fiond buffering the download is best. this
fress
| > up
| > | > the asp.net worker thread quicker.
| > | >
| > | >
| > | > -- bruce (sqlwork.com)
| > | >
| > | >
| > | > <pa***@communit y.nospam> wrote in message
| > | > news:un******** ******@TK2MSFTN GP15.phx.gbl...
| > | >> Hi all, is there a better way to stream binary data stored in a
table
| > in
| > | >> sql 2005 to a browser in .net 2.0? Or is the code same as in .net
| > 1.1?
| > We
| > | >> noticed that in certain heavy load scenarios, every now and then
the
| > | >> client would timeout and have to re-initiate the request...
| > | >>
| > | >> TIA!
| > | >>
| > | >
| > | >
| > |
| > |
| > |
| >
|
|
|

Nov 25 '05 #6
Hi Param,

I've some further communiation with our IIS dev guys and seems the first
layer IIS extending development through pure .net managed code is still not
available for IIS6. We may still have to wait for vista/iis7 which will
support full IIS extending through managed code....

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| X-Tomcat-ID: 38770351
| References: <un************ **@TK2MSFTNGP15 .phx.gbl>
<el************ **@TK2MSFTNGP14 .phx.gbl>
<Ov************ *@TK2MSFTNGP09. phx.gbl>
<06************ **@TK2MSFTNGXA0 2.phx.gbl>
<O3************ **@TK2MSFTNGP14 .phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain
| Content-Transfer-Encoding: 7bit
| From: st*****@online. microsoft.com (Steven Cheng[MSFT])
| Organization: Microsoft
| Date: Fri, 25 Nov 2005 02:38:14 GMT
| Subject: Re: streaming binary data from sql 2005
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| Message-ID: <6V************ **@TK2MSFTNGXA0 2.phx.gbl>
| Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| Lines: 287
| Path: TK2MSFTNGXA02.p hx.gbl
| Xref: TK2MSFTNGXA02.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:3608 30
| NNTP-Posting-Host: tomcatimport2.p hx.gbl 10.201.218.182
|
|
| Thanks for your response Param,
|
| Regarding on developing IIS components through managed code in .net 2.0,
| seems there hasn't detailed public reference. I'll contact some other IIS
| experts to see whether they have any information on this. Also, for
| developing raw ISAPI extension or filters, here're some reference:
|
|
| #Taking the SplashDiving into ISAPI Programming
| http://www.microsoft.com/mind/0197/isapi.asp
|
| #ISAPI Extensions: Creating a DLL to Enable HTTP-based File Uploads with
IIS
| http://msdn.microsoft.com/msdnmag/is...d/default.aspx
|
| Steven Cheng
| Microsoft Online Support
|
| Get Secure! www.microsoft.com/security
| (This posting is provided "AS IS", with no warranties, and confers no
| rights.)
| --------------------
| | From: <pa***@communit y.nospam>
| | References: <un************ **@TK2MSFTNGP15 .phx.gbl>
| <el************ **@TK2MSFTNGP14 .phx.gbl>
| <Ov************ *@TK2MSFTNGP09. phx.gbl>
| <06************ **@TK2MSFTNGXA0 2.phx.gbl>
| | Subject: Re: streaming binary data from sql 2005
| | Date: Thu, 24 Nov 2005 08:24:43 -0600
| | Lines: 238
| | X-Priority: 3
| | X-MSMail-Priority: Normal
| | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| | X-RFC2646: Format=Flowed; Original
| | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| | Message-ID: <O3************ **@TK2MSFTNGP14 .phx.gbl>
| | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| | NNTP-Posting-Host: corp2.lazardgro up.com 70.182.148.88
| | Path: TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP14.phx. gbl
| | Xref: TK2MSFTNGXA02.p hx.gbl
| microsoft.publi c.dotnet.framew ork.aspnet:3607 30
| | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| |
| | Steve, do you have some links to some samples on how to develop an
isapi
| | filter in .net 2.0? I have never attempted that before and dont know
| where
| | to begin. We are working on a large app where pdf files have to be
| securely
| | stored in a sql database & streamed down to users in their browser. We
| are
| | expecting upto 10,000+ simultaneous users at any given time.
| |
| | TIA!
| |
| | "Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
| | news:06******** ******@TK2MSFTN GXA02.phx.gbl.. .
| | > Hi Param,
| | >
| | > I think the Buffering Bruce mentioned means the OutputBuffer setting
for
| | > asp.net web page. We can set it in the @Page directive like:
| | >
| | > <%@Page ..... Buffer="true". .... %>
| | >
| | > or in code through:
| | >
| | > Page_load(...)
| | > {
| | > Response.Buffer Output = true;
| | > }
| | >
| | > The default should be ture. Setting Buffer can help us buffer the
| response
| | > data at serversdie so as to flush them once all the data is complete.
| | > However, this will cause the server memory be comsumed seriously when
| lots
| | > of request executing for large data downloading.... .
| | >
| | > Also, I think it'll be better to implement file download in raw IIS
| isapi
| | > filter or extension and seems .NET 2.0 support developing IIS isapi
| | > components through managed code..
| | >
| | > Thanks,
| | >
| | > Steven Cheng
| | > Microsoft Online Support
| | >
| | > Get Secure! www.microsoft.com/security
| | > (This posting is provided "AS IS", with no warranties, and confers no
| | > rights.)
| | >
| | >
| | >
| | > --------------------
| | > | From: <pa***@communit y.nospam>
| | > | References: <un************ **@TK2MSFTNGP15 .phx.gbl>
| | > <el************ **@TK2MSFTNGP14 .phx.gbl>
| | > | Subject: Re: streaming binary data from sql 2005
| | > | Date: Wed, 23 Nov 2005 20:19:04 -0600
| | > | Lines: 156
| | > | X-Priority: 3
| | > | X-MSMail-Priority: Normal
| | > | X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
| | > | X-RFC2646: Format=Flowed; Response
| | > | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
| | > | Message-ID: <Ov************ *@TK2MSFTNGP09. phx.gbl>
| | > | Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
| | > | NNTP-Posting-Host: corp2.lazardgro up.com 70.182.148.88
| | > | Path:
TK2MSFTNGXA02.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| | > | Xref: TK2MSFTNGXA02.p hx.gbl
| | > microsoft.publi c.dotnet.framew ork.aspnet:3606 09
| | > | X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
| | > |
| | > | Hi, could you please shed some light on "buffering the download" ?
| Here
| | > is
| | > | my code right now. I call the dbchunks2stream method which
essentially
| | > | chunks the data to response.output stream
| | > |
| | > | Public Sub WriteChunks2DB( tablename as string, columnname as
string,
| | > | pkcolumnname as string, pkcolumnval as string, s as stream)
| | > | Dim BUFFER_LENGTH As Integer = 131072 ' chunk size
| | > |
| | > | ' Make sure that Photo is non-NULL and return TEXTPTR to it.
| | > | Dim sqlstr as string = "SET NOCOUNT ON;UPDATE " + tablename + "
| SET
| | > "
| | > +
| | > | columnname + " = 0x0 WHERE " + pkcolumnname + "= '" +
| | > | replacequotes(p kcolumnval) + "';SELECT @Pointer=TEXTPT R(" +
| columnname +
| | > ")
| | > | FROM " + tablename + " WHERE " + pkcolumnname + " = '" +
| | > | replacequotes(p kcolumnval) + "'"
| | > | Dim cmdGetPointer As New SqlCommand(sqls tr, objConnect)
| | > | Dim PointerOutParam As SqlParameter =
| | > | cmdGetPointer.P arameters.Add(" @Pointer", SqlDbType.VarBi nary, 100)
| | > | PointerOutParam .Direction = ParameterDirect ion.Output
| | > | if objConnect.stat e = ConnectionState .Closed Then objConnect.Open
| | > |
| | > | cmdGetPointer.E xecuteNonQuery( )
| | > |
| | > | ' Set up UPDATETEXT command, parameters, and open BinaryReader.
| | > | sqlstr = "UPDATETEXT " + tablename + "." + columnname + "
@Pointer
| | > | @Offset @Delete WITH LOG @Bytes"
| | > | Dim cmdUploadBinary As New SqlCommand(sqls tr, objConnect)
| | > | Dim PointerParam As SqlParameter =
| | > | cmdUploadBinary .Parameters.Add ("@Pointer", SqlDbType.Binar y, 16)
| | > | Dim OffsetParam As SqlParameter =
| | > | cmdUploadBinary .Parameters.Add ("@Offset", SqlDbType.Int)
| | > | Dim DeleteParam As SqlParameter =
| | > | cmdUploadBinary .Parameters.Add ("@Delete", SqlDbType.Int)
| | > | DeleteParam.Val ue = 1 ' delete 0x0 character
| | > | Dim BytesParam As SqlParameter =
| | > | cmdUploadBinary .Parameters.Add ("@Bytes", SqlDbType.Binar y,
| | > BUFFER_LENGTH)
| | > | Dim br As New BinaryReader(s)
| | > | Dim Offset As Integer = 0
| | > | OffsetParam.Val ue = Offset
| | > |
| | > | ' Read buffer full of data and execute the UPDATETEXT statement.
| | > | Dim Buffer() As Byte = br.ReadBytes(BU FFER_LENGTH)
| | > | Do While Buffer.Length > 0
| | > | PointerParam.Va lue = PointerOutParam .Value
| | > | BytesParam.Valu e = Buffer
| | > | cmdUploadBinary .ExecuteNonQuer y()
| | > | DeleteParam.Val ue = 0 ' don't delete any other data
| | > | Offset += Buffer.Length
| | > | OffsetParam.Val ue = Offset
| | > | Buffer = br.ReadBytes(BU FFER_LENGTH)
| | > | Loop
| | > |
| | > | br.Close()
| | > | s.Close()
| | > | objConnect.Clos e()
| | > |
| | > | End Sub
| | > |
| | > | Public Sub DBChunks2Stream (tablename as string, columnname as
string,
| | > | pkcolumnname as string, pkcolumnval as string, byref s as stream)
| | > | Dim ImageCol As Integer = 0 ' position of image column in
| DataReader
| | > | Dim BUFFER_LENGTH As Integer = 131072 ' chunk size
| | > |
| | > | ' Make sure that Photo is non-NULL and return TEXTPTR to it.
| | > | Dim sqlstr as string = "SELECT @Pointer=TEXTPT R(" + columnname
+
| "),
| | > | @Length=DataLen gth(" + columnname + ") FROM " + tablename + " WHERE
"
| +
| | > | pkcolumnname + " = '" + pkcolumnval + "'"
| | > | Dim cmdGetPointer As New SqlCommand(sqls tr, objConnect)
| | > | Dim PointerOutParam As SqlParameter =
| | > | cmdGetPointer.P arameters.Add(" @Pointer", SqlDbType.VarBi nary, 100)
| | > | PointerOutParam .Direction = ParameterDirect ion.Output
| | > | Dim LengthOutParam As SqlParameter =
| | > | cmdGetPointer.P arameters.Add(" @Length", SqlDbType.Int)
| | > | LengthOutParam. Direction = ParameterDirect ion.Output
| | > | if objConnect.stat e = ConnectionState .Closed Then
objConnect.Open
| | > | cmdGetPointer.E xecuteNonQuery( )
| | > | If PointerOutParam .Value Is DBNull.Value Then
| | > | objConnect.Clos e()
| | > | ' Add code to deal with NULL BLOB.
| | > | Exit Sub
| | > | End If
| | > |
| | > | ' Set up READTEXT command, parameters, and open BinaryReader.
| | > | sqlstr = "READTEXT " + tablename + "." + columnname + " @Pointer
| | > @Offset
| | > | @Size HOLDLOCK"
| | > | Dim cmdReadBinary As New SqlCommand(sqls tr, objConnect)
| | > | Dim PointerParam As SqlParameter =
| | > | cmdReadBinary.P arameters.Add(" @Pointer", SqlDbType.Binar y, 16)
| | > | Dim OffsetParam As SqlParameter =
| | > | cmdReadBinary.P arameters.Add(" @Offset", SqlDbType.Int)
| | > | Dim SizeParam As SqlParameter =
| | > cmdReadBinary.P arameters.Add(" @Size",
| | > | SqlDbType.Int)
| | > | Dim dr As SqlDataReader
| | > | Dim Offset As Integer = 0
| | > | OffsetParam.Val ue = Offset
| | > | Dim Buffer(BUFFER_L ENGTH - 1) As Byte
| | > |
| | > | ' Read buffer full of data and write to the file stream.
| | > | Do
| | > | PointerParam.Va lue = PointerOutParam .Value
| | > | ' Calculate the buffer size - may be less than BUFFER_LENGTH
| for
| | > the
| | > | last block.
| | > | If Offset + BUFFER_LENGTH >= Cint(LengthOutP aram.Value) Then
| | > | SizeParam.Value = Ctype((Cint(Len gthOutParam.Val ue) -
| Offset),
| | > | Object)
| | > | Else
| | > | SizeParam.Value = Ctype(BUFFER_LE NGTH, Object)
| | > | End If
| | > | dr = cmdReadBinary.E xecuteReader(Co mmandBehavior.S ingleResult)
| | > | dr.Read()
| | > | dr.GetBytes(Ima geCol, 0, Buffer, 0, Cint(SizeParam. Value))
| | > | dr.Close()
| | > | s.Write(Buffer, 0, Cint(SizeParam. Value))
| | > | Offset += Cint(SizeParam. Value)
| | > | OffsetParam.Val ue = Ctype(Offset, Object)
| | > | Loop Until Offset >= Cint(LengthOutP aram.Value)
| | > |
| | > | s.Close()
| | > | objConnect.Clos e()
| | > |
| | > | End Sub
| | > |
| | > |
| | > |
| | > | TIA!
| | > |
| | > |
| | > | "Bruce Barker" <br************ ******@safeco.c om> wrote in message
| | > | news:el******** ******@TK2MSFTN GP14.phx.gbl...
| | > | > the technique is the same. you will gain a performance boost if
you
| | > switch
| | > | > to a varbinary(max) column over image. there are improvements in
| | > | > transferring the data.
| | > | >
| | > | > note: using asp.net for downloads is problematic. asp.net has a
| | > limited
| | > | > number of request threads and a limited number of connection from
| the
| | > | > asp.net worker process to .net isapi filter. this means you can
not
| | > | > support a lot of simultaneous downloads. even though its heavy on
| | > | > resources, you might fiond buffering the download is best. this
| fress
| | > up
| | > | > the asp.net worker thread quicker.
| | > | >
| | > | >
| | > | > -- bruce (sqlwork.com)
| | > | >
| | > | >
| | > | > <pa***@communit y.nospam> wrote in message
| | > | > news:un******** ******@TK2MSFTN GP15.phx.gbl...
| | > | >> Hi all, is there a better way to stream binary data stored in a
| table
| | > in
| | > | >> sql 2005 to a browser in .net 2.0? Or is the code same as in
net
| | > 1.1?
| | > We
| | > | >> noticed that in certain heavy load scenarios, every now and then
| the
| | > | >> client would timeout and have to re-initiate the request...
| | > | >>
| | > | >> TIA!
| | > | >>
| | > | >
| | > | >
| | > |
| | > |
| | > |
| | >
| |
| |
| |
|
|

Dec 1 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
5694
by: googlegroups | last post by:
I am playing with the XMLHTTPRequest method to perform client/server transactions. I have it set up right now so that when readyState is 4, it takes the XML and processes it. This works great until there is alot of data. In that case, the user will have to wait for the data to come back which may take a minute or so. I don't want the user to have to wait. Is it possible for javascript to periodically (while still receiving more data)...
103
48705
by: Steven T. Hatton | last post by:
§27.4.2.1.4 Type ios_base::openmode Says this about the std::ios::binary openmode flag: *binary*: perform input and output in binary mode (as opposed to text mode) And that is basically _all_ it says about it. What the heck does the binary flag mean? -- If our hypothesis is about anything and not about some one or more particular things, then our deductions constitute mathematics. Thus mathematics may be defined as the subject in...
3
5108
by: Ipsita | last post by:
Hi! I am trying SOAP with DIME attachments in web services. For example say, I have a file resume.pdf stored somewhere on my server. How does the web service send the file to the client, so that the client can store it and also read from it. I am trying out with C# and ASP.NET. Server Side Web Method: -----------------------
3
2341
by: A.M-SG | last post by:
Hi, I have a ASP.NET aspx file that needs to pass large images from a network storage to client browser. The requirement is that users cannot have access to the network share. The aspx file must be the only method that users receive image files.
5
3249
by: Manuel Alves | last post by:
Hi, Is it possible to store media files (like windows .wmv) on SQL Server 2005 and stream it back to the client via media server (not just download it)? Regards, Manuel Alves
8
65832
by: Amjad | last post by:
Hi i am writing a application where i want to browse video file and copy data into stream and send that stream over network...I have develop P2P windows application where i successfully transfer text message to each other but now i want to send video file and play that file on other end...I know the code how to send the stream over the network but basic problem is how open that file as a stream. Thanks
5
3551
by: pmakoi | last post by:
dear all this might be a piece of cake for some of you out there but it is causing me a lot of stress given the fact that there is not enogh documentation out there regarding this topic I am writing a web service that uses soap with attachments to send a large streaming data, The concept works quite well but when I started to test it I got this problem. When my client program calls a method that should return a real time data the...
3
3846
by: masood.iqbal | last post by:
Hi, Kindly excuse my novice question. In all the literature on ifstream that I have seen, nowhere have I read what happens if you try to read a binary file using the ">>" operator. I ran into the two problems while trying to read a binary file. 1). All whitespace characters were skipped 2). Certain binary files gave a core dump
3
4040
by: Brad | last post by:
I have an aspx page that is sending pdf files to client browsers: it uses a filestream to read the pdf file and response.binarywrite to send content to the browser. This has worked great for years in IE, Firefox and Opera on windows, and it works on a Mac with Firefox and Opera. But this fails in Safari with the generic message "A network error occurred while accessing this document". Here is a link to try out ...
0
9463
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9327
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9200
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6747
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6049
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4562
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4823
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2190
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.