Results 1 to 14 of 14

Thread: Write Binary to DB and Read After to create document!

  1. #1

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606

    Write Binary to DB and Read After to create document!

    Why why i read a .jpg for example, write it in a database, then why when i read it back from the db and write it to a file, it add 26 byte and the end ?

    the picture still works, but is 26 byte bigger ?

    When i debug, i can see that it's in the db that the file is 26 bigger(with lngFileSize = rs.Fields("attachementSource").ActualSize), so that's why i write 26 extra byte, but why ?

    tx guys!

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    sebs,

    It's all in your code (which you failed to post). So I can not help you there. You did not mention or show how you put the data tin the db.

  3. #3

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    Originally posted by randem
    sebs,

    It's all in your code (which you failed to post). So I can not help you there. You did not mention or show how you put the data tin the db.
    Yeah, sorry, i thought i would of been a common thing for access to add extra byte in the OLE Field!

    here my code that save it in the DB

    VB Code:
    1. fSize = FileLen(docAttachements(0, X))
    2.                     strSource = Space(fSize)
    3.                     ReDim bytData(intChunk)
    4.                    
    5.                     Open docAttachements(0, X) For Binary As freeF
    6.                                        
    7.                     rs.Open "SELECT * FROM tblAttachements WHERE attachementId=0", conn, adOpenDynamic, adLockPessimistic
    8.                     rs.AddNew
    9.                     rs!attachementQueueId = newId
    10.                     rs!attachementName = docAttachements(0, X)
    11.                    
    12.                     lngCurr = 0
    13.                     While lngCurr < fSize
    14.                         If lngCurr + intChunk >= fSize Then ReDim bytData(intChunk)
    15.                        
    16.                         Get #freeF, , bytData
    17.                        
    18.                         lngCurr = lngCurr + intChunk
    19.                        
    20.                         rs.Fields("attachementSource").AppendChunk bytData
    21.                      Wend
    22.                    
    23.                     Close #freeF

    tx

  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    sebs,

    One problem that I see is with intChunk, It never seems to change yet you use it to write data to the db. In most cases intChunk should change at least once on a large file (the last write to the file), It should get smaller to accommondate for the last part of the file that does not fill the buffer.

    VB Code:
    1. If lngCurr + intChunk >= fSize Then ReDim bytData(intChunk)
    2.  
    3. should read
    4.  
    5. If lngCurr + intChunk >= fSize Then
    6.     intChunk = fSize - lngCurr
    7.     ReDim bytData(intChunk)
    8. End If
    The 26 bytes that you refer to is probably a difference of the last buffer in the file and the actual buffer you use to read the file into.

  5. #5

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    tx for the reply randem,

    i use intChunk to increment my cursor(lngCursor)

    i use the size of bytData to read from the file and write to the db!!

    what do you think?

    i don't think that intChunk = fSize - lngCurr will fix my problem!

  6. #6

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    oh and i'm sorry, because my good version is at home!

    i actually had If lngCurr + intChunk >= fSize Then ReDim bytData(fSize - lngCurr)

    i thought that i would of fix the problem but it only reduce the the space by a little!

  7. #7
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    sebs,

    Why are you incrementing intChunk and what has that to do with the db cursor? intChunk should stay constant and you should not be messing with the db cursor at all (if that's what you mean).

  8. #8

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    no i mean!

    lngCursor is my counter, and i increment it by intChunk !

    i don't touch the DB cursor !

  9. #9
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    sebs,

    Then there are only two other things that could be going wrong. One is the type of field you are using to write to and the database that you are using. What are they?

    Debug the write and check:

    1) Check after each write to the db what the db has for a fieldsize.

    2) Check your last buffer size and counts to see if the check out with each other.

  10. #10

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    tx for the reply, again!

    AS for the Field type, it's OLE Object Field, is that ok ? Shoud it be Memo ?

    and for the field size, everything seem to be fine, i added a watched to my program to debug, and everythin look alright!

    i event tried bytData(fSize - lngCurr-26) and still add the extra bytes!!

    do you know if it's an Access thing ?


    tx again, i appreciate your help

  11. #11
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    sebs,

    The problem is with your OLE Object field. Basically those bytes probably tell the application the correct program to use to open the document. You should be using the Memo field. In other databases the type of field you use would be totally different.


    Use the Memo field an all you problems will go away (well, the one discussed here will).

  12. #12

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    ok, but rs.Fields("attachementSource").AppendChunk bytData does'nt seem to work!!

    should I read all the file, put it in a string or byte array then write it to the memo field ?

  13. #13
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385
    sebs,

    What error are you getting? I remember you can use Ole Object also if you remeber to account for UniCode. Probably better for binary data anyway.

    use the format:

    VB Code:
    1. dbTable.Fields(i).AppendChunk (Chunk())
    2.  
    3. or
    4.  
    5. dbTable!Data.AppendChunk Chunk()
    6.  
    7. This might help also:
    8.  
    9.                    Select Case UniCode
    10.                    
    11.                       Case True
    12.                          Buffer = snpTable.Fields(i).GetChunk(ChunkSize)
    13.                          
    14.                          For k = 1 To ChunkSize
    15.                             Chunk(k - 1) = Asc(Mid(Buffer, k, 1))
    16.                          Next k
    17.                                                                            
    18.                       Case Else
    19.                          Chunk() = snpTable.Fields(i).GetChunk(ChunkSize)
    20.                          
    21.                    End Select

    this works on an OLE Object Field.

  14. #14

    Thread Starter
    Frenzied Member sebs's Avatar
    Join Date
    Sep 2000
    Location
    Aylmer,Qc
    Posts
    1,606
    alright, tx a lot , i'll try that later

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width