Thanks for anyone who tried.
I figured it out.
In my previous code the line
Response.BinaryWrite rs("Attachment")
downloads the whole attachment or datafield at one time. so if it is greater than 4mb it gives a problem.
Now, i am breaking down any field greater than 4mb in to chunks of 1mb and then flushing the buffer.
the new code is below:
Code:
Dim rs
Set rs = Server.CreateObject("ADODB.Recordset")
' opening connection
rs.Open "select [Attachment],[AttachmentType],[contenttype],filename, [filesize] from RequestAttachment where RequestID = " & request("RequestID") & " and attachmentnum=" & ID, connStr, 2, 4
if Not rs.EOF then
if rs("FileSize")< 4194304 then
Response.ContentType = rs("contenttype")
Response.BinaryWrite rs("Attachment")
else
dim aSize , disp
aSize=rs("Attachment").ActualSize
Response.ContentType = rs("contenttype")
while not aSize < 0
disp=rs("attachment").getchunk(1048576)
response.binarywrite disp
response.Flush()
response.Clear()
aSize=aSize-1048576
wend
end if
End If
rs.Close
Set rs = Nothing
it works great for any size of file stored in database.
hope it helps to other ppl.