Search code examples
sql-serveroledbnvarcharntext

OLEDB comparison problem nvarchar against ntext (SQLServer 2005)


I have table Tbl1( SomeName nvarchar(64) )

Over OLEDB I'm trying to select SELECT 1 FROM Tbl1 WHERE SomeName = ?

binding 3 character unicode as parameter causes: DB_E_ERRORSINCOMMAND(0x80040E14L) "The data types nvarchar and ntext are incompatible in the equal to operator"

I have already tried following input bindings:

1) ...
    currentBind.wType         = DBTYPE_VARIANT;
    currentBind.cbMaxLen      = 20
    // where data points to valid VT_BSTR allocated by SysAllocString
...
2) ...
    currentBind.wType         = DBTYPE_WSTR;
    currentBind.cbMaxLen      = 20
    // where data points to valid VT_BSTR allocated by SysAllocString
...

In any way SQLServer treates this parameter as ntext. Any suggestions? Thank you in advance.


Solution

  • Quick and dirty hack: change the query.

    It should look like this:

    SELECT 1 FROM Tbl1 WHERE SomeName = cast(? as nvarchar(64))
    

    Next. I'd profile the code to see what does you provider actually generates in terms of SQL statements. The results could cast some light on the question who's guilty in wrong parameter typing.