473,387 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Problem saving binary data in OLE Object field

Hello.

I am attempting to write binary data from a file to an
OLE Object field, and then write the file back out from
the database. I am reading and writing the files in
binary mode, and using GetChunk and AppendChunk to read
and write binary data from the OLE Object field. I am
using VBA and DAO for this experiment. The OLE Object
field is being used to store Long Binary data.
I have tried four variations as follows:

1. a. Read file data into a byte array
b. AppendChunk byte array to DAO field
c. GetChunk DAO field data into byte array
d. Write byte array to file

This SHOULD be the correct method, but it doesn't
work. I don't know why. The output file is the same
size as the input file. The first half of the output
file matches the first half of the input file.
The second half of the output file is garbage.
2. a. Read file data into a string variable
b. AppendChunk string variable to DAO field
c. GetChunk DAO field data into string variable
d. Write string variable to file

With this approach, the output file is half the
size of the input file. The output file matches the
first half of the input file.

Obviously, the devil here is that VB stores string
data internally as double-byte characters. With
this in mind, I can actually get this approach
to work if I calculate the chunk size based on a
doubled input file size. But this doubles the storage
size in the database, since the data is saved as
double-byte characters.
The other two methods mixed the string and byte
array methods (read string/write byte array,
read byte array/write string). Neither worked.

Suggestions?

Thanks
-Mark
Mar 10 '06 #1
8 8902
"Mark" <no****@thanksanyway.org> wrote:
Hello.

I am attempting to write binary data from a file to an
OLE Object field, and then write the file back out from
the database.


Ok, I checked out the Stephen Lebans examples that
Bri referred me to. It turns out that the code I am using
is clearly based on the ReadBlob() and WriteBlob()
code that he uses from Microsoft's KB article
Q103257 (this code has been modified and re-posted
without credit on dozens of other sites.) I tried using
this sample code verbatim, and it works just like my
code did when using a string variable with GetChunk
and AppendChunk.*

So I guess my question is: is there any way to use
VBA to write binary data to an OLE Object field
without using a BSTR and suffering the storage
penalty of saving the binary data as double-byte
characters?

Thanks again
-Mark

* The only difference is that the code in Q103257
doesn't have to lie about the input file size. I'm not
sure why, but I'll figure it out.


Mar 10 '06 #2
Bri
I wonder if the problems you are having with the String has anything
to do with Unicode. I'm no expert on it but I seem to recall that it
takes twice the space that a traditional string would. Also, the AC97
help states that there is a 65,535 character limit for binary data in a
Memo field. This may be different for AC2K+ versions.

As for the problem with the OLE Object field, I've never used one the
way you are trying, so I don'tknow what is happening to it. Here is a
link to a Lebans page that deals with OLE object fields and files:
http://www.lebans.com/oletodisk.htm

--
Bri

Mar 10 '06 #3
"Bri" <no*@here.com> wrote:
I wonder if the problems you are having with the String has anything to
do with Unicode.


Definitely. I believe the correct way to do this is to use a byte array
instead of a string, and I think I figured out where I got that wrong.
I am now able to store binary data in an OLE Object field with only
about 8k of overhead per record, which isn't too bad for my purposes.
The only remaining glitch is an extra 18 bytes of null data that gets saved
at the end of each record.
Mar 10 '06 #4
I don't know what sample MDB on my site that Bri referred you to but perhaps
you are looking at the wrong one. Just read the data into a Byte array and
write it back out the same way with Get and Put. There are several examples
of this on my site and in my NG postings.

My code works as advertised. Your changing of the existing logic to use
String variables and then stating it does not work is your problem not mine.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"Mark" <no****@thanksanyway.org> wrote in message
news:c7********************@w-link.net...
"Mark" <no****@thanksanyway.org> wrote:
Hello.

I am attempting to write binary data from a file to an
OLE Object field, and then write the file back out from
the database.


Ok, I checked out the Stephen Lebans examples that
Bri referred me to. It turns out that the code I am using
is clearly based on the ReadBlob() and WriteBlob()
code that he uses from Microsoft's KB article
Q103257 (this code has been modified and re-posted
without credit on dozens of other sites.) I tried using
this sample code verbatim, and it works just like my
code did when using a string variable with GetChunk
and AppendChunk.*

So I guess my question is: is there any way to use
VBA to write binary data to an OLE Object field
without using a BSTR and suffering the storage
penalty of saving the binary data as double-byte
characters?

Thanks again
-Mark

* The only difference is that the code in Q103257
doesn't have to lie about the input file size. I'm not
sure why, but I'll figure it out.

Mar 11 '06 #5
"Stephen Lebans" <ForEmailGotoMy.WebSite.-WWWdotlebansdot...@linvalid.com>
wrote:
I don't know what sample MDB on my site that Bri referred you to but
perhaps you are looking at the wrong one. Just read the data into a Byte
array and write it back out the same way with Get and Put. There are
several examples of this on my site and in my NG postings.
I was referring to the code in Microsoft Kb article Q103257. I thought I
found
that from a reference on your site, but now I think I was mistaken about
that.
My apologies. I followed a _lot_ of links today, and it is hard to keep
track
of them all.
My code works as advertised. Your changing of the existing logic to use
String variables and then stating it does not work is your problem not
mine.


Actually, I don't think I have worked with any of the code from your site.
I am sure it is fine. And yes, as you have said, the correct approach is
to use a Byte array. Once again, my apologies.

-Mark
Mar 11 '06 #6
Bri

Stephen Lebans wrote:
I don't know what sample MDB on my site that Bri referred you to but perhaps
you are looking at the wrong one. Just read the data into a Byte array and
write it back out the same way with Get and Put. There are several examples
of this on my site and in my NG postings.

My code works as advertised. Your changing of the existing logic to use
String variables and then stating it does not work is your problem not mine.


Actually, I had referred him to Larry Linson's demo of three methods for
dealing with images:
http://members.tripod.com/accdevel/imaging.htm

I later referred a page on your site (at a time later than the message
that you replied to):
http://www.lebans.com/oletodisk.htm

I'm sure that it was Larry's site he meant to refer to as it shows the
three examples, including the one using the OLE Object field to hold an
image with the resulting huge overhead.

--
Bri

Mar 11 '06 #7
bob

The size of the field contents should be exactly the same as the size of the original file. You can easily
check this by running a query like the following:

SELECT Id, LenB([ImageField]) AS Expr1
FROM tblImages;

Note that the access mdb file grows in 64KB chunks, so there is a variable amount of slack space in there.
Also, variable length data is allocated in 1KB chunks, so there is a little slack for each record, but
this is usually much less than the slack space that the image file would waste in the filesystem.

--
__________________________________________________ _____
http://www.ammara.com/dbpix/access.html
DBPix 2.0: Add pictures to Access, Easily & Efficiently

"Mark" <no****@thanksanyway.org> wrote:
"Bri" <no*@here.com> wrote:
I wonder if the problems you are having with the String has anything to
do with Unicode.


Definitely. I believe the correct way to do this is to use a byte array
instead of a string, and I think I figured out where I got that wrong.
I am now able to store binary data in an OLE Object field with only
about 8k of overhead per record, which isn't too bad for my purposes.
The only remaining glitch is an extra 18 bytes of null data that gets saved
at the end of each record.


Mar 11 '06 #8
"Bri" <no*@here.com> wrote:

Stephen Lebans wrote:
I don't know what sample MDB on my site that Bri referred you to but
perhaps you are looking at the wrong one. Just read the data into a Byte
array and write it back out the same way with Get and Put. There are
several examples of this on my site and in my NG postings.

My code works as advertised. Your changing of the existing logic to use
String variables and then stating it does not work is your problem not
mine.


Actually, I had referred him to Larry Linson's demo of three methods for
dealing with images:
http://members.tripod.com/accdevel/imaging.htm


Yes, that is where I found the references to Q103257. I did not want
to identify the source in my apology to Stephen, lest I incur the
unhappiness
of yet another online consultant.

-Mark
Mar 11 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: G-Factor | last post by:
Hi all I've just started learning about saving files. I got bit of a problem. The following code gives me an error about incompatible types. (Cannot covert from class character to char *). I...
4
by: Jerivix Entadi | last post by:
I'm attempting to create an application to work with a fluid database of people. I'm doing this in a command line, text-based manner. I need to know two things: 1) How do I save data, perhaps a...
4
by: dale zhang | last post by:
Hi, I am trying to save and read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp Right now, I saved images without any...
0
by: Tommy Christian | last post by:
Hi! Anyone who knows about saving serialized data to database, coz I have a problem with that. If I just serialize my session data and then deserialize it, it works. But when I save it...
3
by: Ipsita | last post by:
Hi! I am trying SOAP with DIME attachments in web services. For example say, I have a file resume.pdf stored somewhere on my server. How does the web service send the file to the client, so that...
3
by: Tony Lugg | last post by:
I have an application with a document management form. When users add documents to the form, I call the API function SHGetFileInfo to get the associated large and small icons for the file. These...
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
5
by: Mark | last post by:
I have a VB 6 program that I have saved an audio file to using DAO and the appendchunk as is shown at http://support.microsoft.com/kb/103257/EN-US/. ; I have it working fine in that app (it saves...
4
by: Pedro Leite | last post by:
Good Afternoon. the code below is properly retreiving binary data from a database and saving it. but instead of saving at client machine is saving at the server machine. what is wrong with my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.