0

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.

Welbog
  • 59,154
  • 9
  • 110
  • 123
Dewfy
  • 23,277
  • 13
  • 73
  • 121

1 Answers1

1

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
  • 2,388
  • 15
  • 15
  • Yes it helps. SQL Profiler exactly shows that my ? treated as ntext (see @p2 bellow): declare @p1 int set @p1=21 exec sp_prepexec @p1 output,N'@P1 bigint,@P2 ntext,@P3 bigint',N' – Dewfy Aug 05 '09 at 17:05
  • 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 Aug 05 '09 at 18:44
  • Unfortunately provider is "the Great and Powerful" MSSQL Server 2005 native driver. – Dewfy Aug 06 '09 at 11:33