Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

VARBINARY(N) produces error 16911 with sp_cursor cid, 40, 1

$
0
0
Using SQL Native Client ODBC 11 with SQL Server 2014, trying to fetch VARBINARY(4) datawith SQLGetData() after binding with SQLBindCol (... SQL_DATA_AT_EXEC), the serverreturns error 16911 "fetch: The fetch type refresh cannot be used with forward only cursor"The same code works find with VARBINARY(MAX) and VARCHAR(MAX), fetch LOBs datain pieces... So why does the server produce this error with a VARBINARY(N) ???Here the Transac-SQL code (simulating ODBC client calls) to reproduce the problem:Try following SQL (works with table t11 using VARBINARY(MAX)):create table t11 ( pk int, vb_4 varbinary(max))insert into t11 values ( 1, cast(256 as varbinary(max)) )insert into t1 values ( 2, cast(4096 as varbinary(max)) )declare @p1 int, @p2 int, @p3 int, @p4 int, @p5 intset @p1=0exec sp_cursorprepare @p1 output,NULL,N'select * from t11 order by pk', 1, 16400, 8193set @p2=0set @p3=16set @p4=1set @p5=-1exec sp_cursorexecute @p1 ,@p2 output,@p3 output,@p4 output,@p5 outputexec sp_cursoroption @p2,2,N'mycurs1'exec sp_cursorfetch @p2,2,0,1exec sp_cursor @p2,40,1exec sp_cursorunprepare @p1But this sequence fails (using t12 with VARBINARY(4))create table t12 ( pk int, vb_4 varbinary(4))insert into t12 values ( 1, cast(256 as varbinary(4)) )insert into t12 values ( 2, cast(4096 as varbinary(4)) )declare @p1 int, @p2 int, @p3 int, @p4 int, @p5 intset @p1=0exec sp_cursorprepare @p1 output,NULL,N'select * from t12 order by pk', 1, 16400, 8193set @p2=0set @p3=16set @p4=1set @p5=-1exec sp_cursorexecute @p1 ,@p2 output,@p3 output,@p4 output,@p5 outputexec sp_cursoroption @p2,2,N'mycurs2'exec sp_cursorfetch @p2,2,0,1exec sp_cursor @p2,40,1exec sp_cursorunprepare @p1Seb

Viewing all articles
Browse latest Browse all 3145

Trending Articles