Welcome to WebmasterWorld Guest from

Forum Moderators: ocean10000

Message Too Old, No Replies

Calling Stored Procedure to Read BLOBS

3:42 pm on Mar 9, 2016 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 8, 2004
posts: 60
votes: 0

I am writing a script (in ASP 'Classic' VB) to call a stored procedure, which will read a binary (BLOB).
Does anyone have any ideas or input on the best way to proceed with this?
I have used the code ("Code A" below) for my non-BLOB sprocs, and it's always worked nicely.
It uses ADODB.Command - would it be best to use this appoach or maybe go to ADODB.Recordset, or a mix of the two?

Up to now, the old way of reading BLOBs was to use the ADODB.Recordset method like in "Code B" (below).

Thanks very much for your help and input.
Code A
'-------------------------------stored procedure login test - begin
' set up adovbs variables (for stored procedures) - begin
Const adVarChar = 200
Const adDate = 7
Const adParamInput = &H0001
' set up adovbs variables (for stored procedures) - end

Set objCommandSec = CreateObject("ADODB.Command")

With objCommandSec
Set .ActiveConnection = objConnection
.CommandText = "[log_in_a]"
.CommandType = 4

.Parameters.Append .CreateParameter("@ID",adVarChar, adParamInput,50)

.Parameters("@ID") = strID '/////
set objComm = .Execute
End With

' Clean up
set objCommandSec = nothing
set rs = nothing
set objComm = nothing
'-------------------------------stored procedure login test - end

Code B
BlockSize = 4096

Response.ContentType = objRS("ContentType")
' let the browser know the file name
Response.AddHeader "Content-Disposition", "attachment;filename=" & Trim(objRS("filename"))

Set Field = objRS("image_blob")

FileLength = Field.ActualSize
Response.AddHeader "Content-Length", FileLength
NumBlocks = FileLength \ BlockSize

LeftOver = FileLength Mod BlockSize
If LeftOver > 0 Then
Response.BinaryWrite Field.GetChunk(LeftOver)
End If
For intLoop = 1 To NumBlocks
Response.BinaryWrite Field.GetChunk(BlockSize)
12:25 am on Mar 10, 2016 (gmt 0)


WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

joined:Jan 14, 2004
votes: 3

It has been over 15 years since I last touched asp classic code with vbscript so I am a bit rusty.

"Code A" below
set objComm = .Execute

objComm <-- is your record set returned from the command object, which is the equivalent to "objRS" in "Code B".

So it shouldn't be that much a problem using Records sets with command objects.