Writing to a CLOB in Unicode mode in Oracle 10
Writing to a CLOB in Unicode mode in Oracle 10
I am using OraDirect .NET in Direct mode (direct=true) to talk to an Oracle 10 database that is configured for UTF-16 (Unicode). I am trying to write a 12 Kbyte string to a column in the database which has type CLOB.
If I follow the example provided of writing the CLOB and set the value of Size to the maximum that the CLOB can support
parameter.Size=100000;
parameter.Value = pXmlString;
parameter.Direction = ParameterDirection.Input;
The first couple of thousand characters are fine when I read it back, but the remaining are garbage.
If I use the following to compute the size
UnicodeEncoding encoding = new UnicodeEncoding();
byteArray = encoding.GetBytes(pXmlString);
parameter.Size = byteArray.Length;
parameter.Value = pXmlString;
parameter.Direction = ParameterDirection.Input;
I still get the same garbage.
If I do
myLob = new OracleLob(this._connection as OracleConnection, OracleDbType.Blob);
UnicodeEncoding encoding = new UnicodeEncoding();
byte[] data = encoding.GetBytes(pXmlString);
myLob.Write(data, 0, data.Length);
parameter.Value = myLob;
parameter.Direction = ParameterDirection.Input;
everything is garbage.
The last example however works with Oracle 9 in Unicode mode.
Can you tell me how would I go about saving Unicode data into the Oracle 10 database using the OraDirect.NET driver without having the be corrupted when I retrieve it.
Thank you,
Irfan
If I follow the example provided of writing the CLOB and set the value of Size to the maximum that the CLOB can support
parameter.Size=100000;
parameter.Value = pXmlString;
parameter.Direction = ParameterDirection.Input;
The first couple of thousand characters are fine when I read it back, but the remaining are garbage.
If I use the following to compute the size
UnicodeEncoding encoding = new UnicodeEncoding();
byteArray = encoding.GetBytes(pXmlString);
parameter.Size = byteArray.Length;
parameter.Value = pXmlString;
parameter.Direction = ParameterDirection.Input;
I still get the same garbage.
If I do
myLob = new OracleLob(this._connection as OracleConnection, OracleDbType.Blob);
UnicodeEncoding encoding = new UnicodeEncoding();
byte[] data = encoding.GetBytes(pXmlString);
myLob.Write(data, 0, data.Length);
parameter.Value = myLob;
parameter.Direction = ParameterDirection.Input;
everything is garbage.
The last example however works with Oracle 9 in Unicode mode.
Can you tell me how would I go about saving Unicode data into the Oracle 10 database using the OraDirect.NET driver without having the be corrupted when I retrieve it.
Thank you,
Irfan
Issuing the following SQL returns the character sets below.
select * from nls_database_parameters where parameter like '%CHARACTERSET'
NLS_CHARACTERSET AL32UTF8
NLS_NCHAR_CHARACTERSET AL16UTF16
Yes I have Unicode=true in my connection string.
I have also tried using UTF8Encoding class in the examples above that I have provided without any luck.
select * from nls_database_parameters where parameter like '%CHARACTERSET'
NLS_CHARACTERSET AL32UTF8
NLS_NCHAR_CHARACTERSET AL16UTF16
Yes I have Unicode=true in my connection string.
I have also tried using UTF8Encoding class in the examples above that I have provided without any luck.
Problem still exists...
Hi Alexey,
Irfan is not available for few weeks so I am following up on the issue.
The problem still exists with the latest version of the drivers. If however, I change
myLob = new OracleLob(this._connection as OracleConnection, OracleDbType.Blob);
to
myLob = new OracleLob(this._connection as OracleConnection, OracleDbType.Clob);
, I do not get garbage data but instead the data gets truncated in Oracle 10g Unicode = True and in Oracle 9i Unicode = True, I get ORA-06505 error.
If I do not make this change,
Oracle 9i (Unicode) works and Oracle 10g (Unicode) gives me junk characters even in the latest drivers.
I have a sample project that connects to 10g (Unicode) where the string gets truncated. Please let me know how to send you the sample project.
Any help will be appreciated. Thanks!
Irfan is not available for few weeks so I am following up on the issue.
The problem still exists with the latest version of the drivers. If however, I change
myLob = new OracleLob(this._connection as OracleConnection, OracleDbType.Blob);
to
myLob = new OracleLob(this._connection as OracleConnection, OracleDbType.Clob);
, I do not get garbage data but instead the data gets truncated in Oracle 10g Unicode = True and in Oracle 9i Unicode = True, I get ORA-06505 error.
If I do not make this change,
Oracle 9i (Unicode) works and Oracle 10g (Unicode) gives me junk characters even in the latest drivers.
I have a sample project that connects to 10g (Unicode) where the string gets truncated. Please let me know how to send you the sample project.
Any help will be appreciated. Thanks!