Focal Point
[SHARING] OLE DB errors when using CTE's on SQL Server + SOLUTION

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/8737051226

July 12, 2012, 05:56 AM
Wep5622
[SHARING] OLE DB errors when using CTE's on SQL Server + SOLUTION
This is a bit of a "note to self", but I've run into this error a couple of times now and the solution is not obvious from the error message. Searching the forums on the error also didn't provide an immediate answer. Until now Smiler

If you use a CTE (Common Table Expression), such as:
ENGINE SQLMSS SET DEFAULT_CONNECTION &CONNECTION
SQL SQLMSS PREPARE SQLOUT FOR
WITH cte1 AS (
   SELECT 1 AS WHICH, A, B, C FROM TABLE1 WHERE C IS NOT NULL
   UNION
   SELECT 2 AS WHICH, A, B, 'dummy' AS C FROM TABLE1 WHERE C IS NULL
)
SELECT WHICH, A, B, C FROM cte1
ORDER BY C
;
END

TABLE FILE SQLOUT
PRINT *
END


You may get an error:
 (FOC1400) SQLCODE IS -1 (HEX: FFFFFFFF)
 : Microsoft SQL Native Client: [] Multiple-step OLE DB operation generated
 :  errors. Check each OLE DB status value, if available. No work was done.
 L    (FOC1406) SQL OPEN CURSOR ERROR.  : SQLOUT


This is NOT (necessarily) because there's any error in your query. I was scratching my head after executing this query just fine from another (Java-based) SQL client, until I found an old post (by myself, even!) that contained the solution - but that was about a different topic.

The solution: You need to add below line to your ENGINE initialisation code to make WebFOCUS perform the query entirely in the SQL client (or something):
ENGINE SQLMSS SET CURSORS CLIENT



So it becomes:
ENGINE SQLMSS SET CURSORS CLIENT
ENGINE SQLMSS SET DEFAULT_CONNECTION &CONNECTION
SQL SQLMSS PREPARE SQLOUT FOR
WITH cte1 AS (...)



WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
February 11, 2015, 04:10 PM
Josh Morel
I was looking for help on this and was glad to find this. Later on, I found I could change this by default under the Server Admin Adapter Connection Settings. I changed Controlling Session Parameters>CURSORS to 'CLIENT' (nothing was previously selected).




WebFOCUS 8004
Windows Server 2008 R2 Standard 64-bit
All Outputs