Strange Unicode-related bug with Oracle

  • Thread starter Jens Christian Mikkelsen
  • Start date
J

Jens Christian Mikkelsen

I have this strange problem with Oracle and Unicode. First, some data
on my product versions:

Microsoft Visual Studio .NET 2003 (i.e. framework 1.1)
Oracle 9i on client and server
MDAC 2.8

I have a table called "languagetext" holding approximately 4000
records, with a definition like this:

Name Null? Type
------------- -------- ----------------------------
TEXTID NOT NULL NUMBER(8)
LANGUAGE NOT NULL CHAR(2)
TEXT NOT NULL NVARCHAR2(4000)

The language field is always either "en", "da", "sv", "no" or "nl". I
also have a small VB.NET program reading the table using an
OracleDataReader, which works for the first records, but after a
number of records, the encoding seems to go haywire. Some example
code:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim oConn As New OracleConnection
oConn.ConnectionString = "Server=gbpd;Uid=foo;Pwd=bar"
oConn.Open()

Dim oCmd As OracleCommand = oConn.CreateCommand()
oCmd.CommandText = "SELECT textid, language FROM languagetext"
Dim oReader As OracleDataReader = oCmd.ExecuteReader()
Dim sLang, sLang2 As String
Dim i, iCharCode As Integer

While oReader.Read
sLang = CStr(oReader("language"))
Select Case sLang
Case "en", "da", "sv", "no", "nl"
' Do nothing
Case Else
iCharCode = AscW(sLang)
sLang2 = ChrW(iCharCode Mod 256) & ChrW(iCharCode \
256)
Stop
End Select
i += 1
End While

oReader.Close()
oConn.Close()
End Sub

This small program seems to read the first 2048 records correctly, but
for the 2049th record, I get a high Unicode character 0x6164, which is
actually the ASCII codes for "d" and "a" packed into one 16-bit
integer. So it seems that after 2048 records, the system believes that
the "language" column is Unicode too? (This is what I'm trying to fix
with the sLang2 code.)

Has anyone else experienced the same strange problem?

Regards,
Jens Christian Mikkelsen
 
J

Jens Christian Mikkelsen

Hello again,

I just re-tested with Framework 1.0 on the exact same machine, and it
works perfectly there!

So it appears to be a Framework 1.1 bug? Spooky.

/Jens
 
J

Jens Christian Mikkelsen

Another (strange) observation: If I replace the command text with the
following, then the code works under 1.1 too.

oCmd.CommandText = "SELECT textid + 0, language FROM languagetext"

It appears that a select with expressions is treated very differently
from a select without.

/Jens
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top