LawrenceY
asked on
MSSQL - VB
I am using MSSQL to store an image/tiff file, under the image datatype. I want to retrieve the image file from the database for viewing through VB. The codes below is to retrieve the image file, which is rather correct if I am not mistaken.
ChunkSize = objRS("Fax").ActualSize
ImageFile = (objRS("Fax").GetChunk(Chu nkSize))
The problem is if the actual image size is 10000 bytes, all I get to retrieve is 5000 bytes, 50% of the actual file size. I tried it using different file formats but it is still the same. When I edited the retrieved image file's contents... I found garbled characters different from the actual image file's contents. Anybody know the answer to this and the way to solve it. Please any ideas... I tried MS Knowledgebase and Technet but I cant find the solution.
ChunkSize = objRS("Fax").ActualSize
ImageFile = (objRS("Fax").GetChunk(Chu
The problem is if the actual image size is 10000 bytes, all I get to retrieve is 5000 bytes, 50% of the actual file size. I tried it using different file formats but it is still the same. When I edited the retrieved image file's contents... I found garbled characters different from the actual image file's contents. Anybody know the answer to this and the way to solve it. Please any ideas... I tried MS Knowledgebase and Technet but I cant find the solution.
ASKER
The codes cant work. Below is my actual program codes.
objRS.MoveFirst (my database)
For i = 1 To numrecords (total records)
ChunkSize = objRS("Image").ActualSize
FaxMailData = objRS("Image").GetChunk(Ch unkSize)
Image2 = Image ChunkSize2 = Len(Image2)
MsgBox "ActualSize=" & ChunkSize & " | " & "ConvertedSize=" & ChunkSize2 'Debug
MsgBox FaxMailData() 'Debug
objRS.MoveNext
Next i
Find anything wrong with it? Please anybody tell me. Thanks.
objRS.MoveFirst (my database)
For i = 1 To numrecords (total records)
ChunkSize = objRS("Image").ActualSize
FaxMailData = objRS("Image").GetChunk(Ch
Image2 = Image ChunkSize2 = Len(Image2)
MsgBox "ActualSize=" & ChunkSize & " | " & "ConvertedSize=" & ChunkSize2 'Debug
MsgBox FaxMailData() 'Debug
objRS.MoveNext
Next i
Find anything wrong with it? Please anybody tell me. Thanks.
give me the Dim's. each variable declaration
</wqw>
</wqw>
You should use getchunk in a loop to retrieve the data in pieces rather than by trying to get the whole lot. There are restrictions on the number of bytes that can be extracted from a field in one go, this is defaulted to 5K unless you use settextsize etc which can prove a real pain!
This example gets the data in 1K blocks from the field.
conChunkSize = 1000
lngLogoSize = rstPubInfo!logo.ActualSize
Do While lngOffset < lngLogoSize
varChunk = rstPubInfo!logo.GetChunk(c onChunkSiz e)
varLogo = varLogo & varChunk
lngOffset = lngOffset + conChunkSize
Loop
This example gets the data in 1K blocks from the field.
conChunkSize = 1000
lngLogoSize = rstPubInfo!logo.ActualSize
Do While lngOffset < lngLogoSize
varChunk = rstPubInfo!logo.GetChunk(c
varLogo = varLogo & varChunk
lngOffset = lngOffset + conChunkSize
Loop
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ImageFile = (objRS("Fax").GetChunk(Chu
should be
ImageFile = objRS("Fax").GetChunk(Chun
and ImageFile must be
Dim ImageFile() As Byte
The parentheses convert the byte array to string which is the intrinsic way in VB to convert from Unicode to Ascii. so you get 1 byte for every 2 bytes :-))
Let me know if this works for you.
HTH,
</wqw>