views:

96

answers:

2

Hi,

I am using NHibernate to query an Oracle 8i database. The problem is that all the strings in the returned objects are postfixed with special characters. For e.g.

CUSTOMER,ONE�������

The nhibernate field type is AnsiString and the Oracle datatype is CHAR(20) and the Character set is CHAR_CS. I am totally new with Oracle so i don't have a clue whats going on :(

+4  A: 

CHAR(20) means the field is padded as necessary to be exactly 20 characters long. The padding character is a blank.

There must be a problem somewhere in your character set settings if padding characters appear as question marks. You may find more insight on your problem here.

What you need here is to trim the returned strings, or better yet move to VARCHAR2(20).

Mac
Yes that's right. I generally stick to VARCHAR unless I know that something is fixed length like a 3 character currency code.
pjp
Is this the only solution? It'd be quite painful to trim all the strings before usage specially with databinding.
Ali Kazmi
Nope. Unless you can have your own queries and add TRIM on every CHAR field. VARCHAR2 is really the type you wanted there, not CHAR.
Mac
I just queried the database directly through ADO.NET (OleDbConnection) and it works perfectly. No special characters at the end. Why??? :(
Ali Kazmi
A: 

Hi,

I couldn't find a proper solution for this issue but changing the nhibernate driver from 'OracleClientDriver' to 'OleDbDriver' solved this issue. Still if anyone knows how to tackle this issue properly please let me know as I don't like using the OldDbDriver for accessing Oracle because of possible compatibility issues.

Ali Kazmi
Well, I'm pretty sure you are still having your strings padded, but with real blanks instead of invalid characters.
Mac