From my application written with Delphi 2009, I am reading from and writing to an IBM DB2 database using ADO, the ODBC Provider for ADO, and ODBC:
Application -> ADO (Win32) -> ODBC-Provider for ADO -> ODBC -> (net) -> DB2 (Windows)
Now, my application need to store unicode data. So I set my database codepage to UTF-8. Delphi handles strings in UTF-16 internally and passes them as multi-byte-characters to COM. So I should be fine on encoding on the application's side.
Inserting non-ansi-chars in a VARCHAR db field works fine, they are displayed correctly by the DB2 management console (which is a Java application using, I figured, JDBC). In my application (or an开发者_Python百科y other test application I wrote that uses ADO queries), I get only a sequence of #$1A bytes for VARCHAR fields with unicode characters in them.
Strangely, the same application works fine if the backend is a Microsoft SQL database. Retrieving ANSI-compliant character strings also isn't a problem for DB2.
In the DB2 documentation it says that the DB2 ODBC drivers responds with unicode characters if an application calls the suffix-W ODBC APIs. Is it possible that under certain circumstances the ODBC Provider for ADO doen't trigger those functions but instead uses the ANSI functions? I tried setting a client codepage in the ADO connection string and the ODBC driver settings without success, although I could've done that the wrong wav.
I had a similar problem. I have added DISABLEUNICODE=0
to my connection string and it resolved it for me.
精彩评论