views:

240

answers:

1

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.

+1  A: 

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.

AlexS
Yes it helps.SQL Profiler exactly shows that my ? treated as ntext (see @p2 bellow):declare @p1 intset @p1=21exec sp_prepexec @p1 output,N'@P1 bigint,@P2 ntext,@P3 bigint',N'
Dewfy
Then I'd try to either update the provider if possible (hoping that it will do its' job better) or stick with the 'quick and dirty hack'.
AlexS
Unfortunately provider is "the Great and Powerful" MSSQL Server 2005 native driver.
Dewfy