PRB: GetChunk Corrupts Binary Data on Win98/NT4 SP4 (199929)
The information in this article applies to:
- Microsoft Office XP Developer
- Microsoft Office 2000 Developer
- Microsoft Access 97
- ActiveX Data Objects (ADO) 2.0
- Microsoft Visual Basic Learning Edition for Windows 5.0
- Microsoft Visual Basic Learning Edition for Windows 6.0
- Microsoft Visual Basic Professional Edition for Windows 5.0
- Microsoft Visual Basic Professional Edition for Windows 6.0
- Microsoft Visual Basic Enterprise Edition for Windows 5.0
- Microsoft Visual Basic Enterprise Edition for Windows 6.0
This article was previously published under Q199929 SYMPTOMS
When using the Data Access Objects (DAO), Remote Data Objects (RDO) or the ADO GetChunk method, on a long binary field of a Microsoft Access database, binary data may appear corrupt if the binary information previously stored was read from disk using a String (BSTR) variable instead of a Byte array. The problem occurs under one of the following conditions: - You recently upgraded your computer to Windows 98 or Windows NT version 4.0 SP4. Previously stored data now appears corrupt.
-or- -
You are using a shared database. The corruption occurs when the binary data was stored by clients running on Windows 95 or Windows NT 4.0 SP3, and then extracted by clients running Windows 98 or Windows NT 4.0 SP4 or vice versa.
CAUSE
The problem is that the information stored to the database is mistakenly being converted to Unicode before being stored. The "corruption" occurs when reading the information from disk using the Visual Basic or Visual Basic for Applications Get statement.
By design, the Get statement relies on the data type of the variable to determine how the information should be read into Visual Basic. If you pass a String (BSTR) variable to the function, Visual Basic identifies the information as being a text string, and converts it to Unicode. However, since the data is binary and not text, this conversion corrupts the data before it is ever stored to the database.
Although binary data stored in Unicode format can be "decoded" in some cases, it requires that the Unicode symbol table used to map 1-byte ANSI characters to 2-byte Unicode characters be the same for both the conversion to and the conversion from Unicode. Due to the recent addition of the European Currency symbol, the symbol table for Windows 98 and Windows NT 4.0 SP4 is different from those used previously. These changes will have no effect on text strings, but can effect binary data mistakenly converted to Unicode.
RESOLUTIONNOTE: Binary data should never be converted to/from Unicode. To avoid the possibility of such conversions, do not use BSTRs when working with binary data. Instead use a Byte array. For example:
Dim yBinaryData() As Byte
Open "C:\MyFile.dat" For Binary As #1
ReDim yBinaryData(LOF(1)) As Byte
Get #1, , yBinaryData
Close #1
rs.Fields("MyData").AppendChunk yBinaryData
For databases with "corrupted" data already stored, you will need to extract the information on a Windows 98 or Windows NT 4.0 SP3 computer and restore it correctly using a byte array.
STATUS
This behavior is by design.
REFERENCES
For additional information about using GetChunk and AppendChunk, please see the following article in the Microsoft Knowledge Base:
153238 HOWTO: Use GetChunk and AppendChunk Methods of RDO Object
Modification Type: | Major | Last Reviewed: | 12/12/2003 |
---|
Keywords: | kbAutomation kbprb kbRDO KB199929 |
---|
|