Using AppendChunk problem

Using AppendChunk problem

Post by Paul Barlo » Sun, 20 Jan 2002 05:17:16


I am using the appendchunk method to insert pdf,doc,html files into an image
column in a SQL Server database.
I've noticed however that the object size in the database is bigger than the
physical file on disk.  It appears that after each valid character a space
is added, so for html file looks something like this < H E A D> W H A T E V
E R (Hex character 20 is being inserted)

I can extract the data using the getchunk method but I am not happy with the
extra character being added.  Also if other systems need to extract the data
the data being stored is not obviously exactly as the original file is.  I
was wondering if anybody else has encounted this and if there is a fix/
other way of getting binary data into a image field?

I've included the functions I am using to read/write data below.

Any help would be very much appreciated.


Paul B

Public Sub ColumnToFile(Col As adoDB.Field, DiskFile As String)
    'Retrieves data from the database and puts it into a temp file on
    'the hard drive.
    'The size of the chunk is in the variable BLOCKSIZE (4096).

   Dim NumBlocks As Long  'Holds the number of chunks.
   Dim LeftOver As Long   '# of chars left over after last whole chunk.
   Dim strData As String
   Dim DestFileNum As Long
   Dim I As Long
   Dim ColSize As Long

   'Make sure that you aren't in an empty recordset.
    If Not grsRepository.EOF And Not grsRepository.BOF Then
         ColSize = Col.ActualSize

   'If filelength > 0, then it is soiled:
   ' throw away contents.
    If Len(Dir$(DiskFile)) > 0 Then
      Kill DiskFile
    End If

    DestFileNum = FreeFile
    Open DiskFile For Binary As DestFileNum
    NumBlocks = ColSize \ BLOCKSIZE
    LeftOver = ColSize Mod BLOCKSIZE

    'Now Write data to the file in chunks.
     For I = 1 To NumBlocks
         strData = String(BLOCKSIZE, 0)
         strData = Col.GetChunk(BLOCKSIZE)
         Put DestFileNum, , strData
     Next I

     strData = String(LeftOver, 0)
     strData = Col.GetChunk(LeftOver)
     Put DestFileNum, , strData

     Close DestFileNum
     End If
End Sub


Sub FileToColumn(Col As adoDB.Field, DiskFile As String)
     'Takes data from the temp file and saves it to the database.

       Dim strData As String
       Dim NumBlocks As Long
       Dim FileLength As Long
       Dim LeftOver As Long
       Dim SourceFile As Long
       Dim I As Long

       SourceFile = FreeFile
       Open DiskFile For Binary Access Read As SourceFile
       FileLength = LOF(SourceFile)

       If FileLength = 0 Then
          Close SourceFile
          MsgBox DiskFile & " Empty or Not Found."
         NumBlocks = FileLength \ BLOCKSIZE
         LeftOver = FileLength Mod BLOCKSIZE
         Col.AppendChunk Null
         strData = String(BLOCKSIZE, 0)

         For I = 1 To NumBlocks
            Get SourceFile, , strData
            Col.AppendChunk strData
         Next I

         strData = String(LeftOver, 0)
         Get SourceFile, , strData
         Col.AppendChunk strData
         Close SourceFile
       End If
End Sub


1. Problem reading strings from Access7 using getchunk/appendchunk/string datatype

There is something strange going on:

I'm reading binary files with VB5 to and from Access 7 databases,
using getchunk, appendchunk and the string datatype.

It's working fine on all systems (Win 95, Win NT 3..51) except on my own pc:
since a few months I cannot retrieve the files out of the database

I've compared the binary files and at some point there is a difference.
It must be something in the handling of strings, but I was using exactly the
same VB executable.
If I'm saving new files with my own PC I can retreive them correctly there
not on other machines.
I've upgraded to Win 98 lately but the problem remains the same!

I've been wondering what's wrong with my PC.
- A damaged DLL? I could not find one.
- A wrong registry setting? Which one?!
- Is there some setting that tells the system how to handle strings and
incluences VB?

Any hints would be greatly appreciated.

Thanks! Hans.

| "My loved Shelley, now ten years at this season did we first meet,     |
| and these were the very scenes - that churchyard with its sacred tomb, |
| where first love shone in your dear eyes"                              |
|                                                                        |
| Mary Shelley in her journal, written at her mother's grave (1824)      |

| Visit The Androom Experience at          |

2. Sync with SqlServer

3. Using appendchunk/getchunk

4. JDBC types for getting a ResultSet from a CallableStatement

5. Getting Error Message when using AppendChunk with Parameter Object

6. Oracle bookshop publications info required

7. Error when using RecordSet.Update after AppendChunk

8. Illustra Vacuum problem

9. Can't write to LONG RAW using APPENDCHUNK , ASP

10. Using GetChunk and AppendChunk methods.

11. Appendchunk fails using ADO and SQL7

12. AppendChunk using Perl

13. Using AppendChunk; Help requested