We have a stored procedure running on SQL Server that exchanges data with an Oracle table, through a linked server, the versions of both products are at the end of this post.
In our stored procedure, the name of the linked server is obtained dynamically, and access to Oracle is done within an
EXECThe first access to the linked server happens by writing data in Oracle, as follows:
DECLARE @lksrv VARCHAR(300);
SELECT @lksrv = Value FROM cfg;
EXEC('
INSERT INTO ' + @lksrv + 'EXTERNALTABLE(TSTATUS, MSGGER, FIELD1, FIELD2, ...)
SELECT 0 AS TSTATUS, NULL AS MESSAGE, FValue1, FValue2, ...)
FROM InternalTable
');
- Afterwards, we read results from Oracle based on the value of
TSTATUS, as follows:
EXEC('
INSERT INTO ##TemporaryValues (FiedlRet1, FiedlRet2...)
SELECT E.RETVALUE1, E.RETVALUE2...
FROM ' + @lksrv + 'EXTERNALTABLE and
WHERE e.TSTATUS IN (2, 3, 25, 29)
');
- Finally, we mark the returns already processed
EXEC('
UPDATE and SET TSTATUS = t.FinalResult
FROM ' + @lksrv + 'EXTERNALTABLE and
INNER JOIN ##TemporaryValues t ON t.KEY = e.KEY
');
I found many previous questions about differences in how direct code works in Management Studio versus ADO, but none of them were specifically about linked server.
And my code, if I comment out the linked server access, works perfectly in both cases.
Information about SQL Server:
Microsoft SQL Server 2016 (SP2-CU15) (KB4577775) - 13.0.5850.14 (X64) Sep 17 2020 22:12:45
Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows Server 2019 Standard 10.0 <X64> ( Build 17763: ) (Hypervisor)
Information about Oracle:
ODA version:Product Name: ODA X8-2L
Bank version:Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production Version 19.14.0.0.0
Patch installed:
32327201;R
- DBMS - DSTV36 UPDATE - TZDATA2020E
- 31324507;INSTANCE CRASHED AFTER SEVERAL PROCESS HANG DUE TO LATCH CACHE BUFFERS CHAINS
- 32374616;ALLOW UNDERSCORE AND HYPHEN FOR ORACLE_SID
- 30870248;UNEXPECTED W000...FAILED TO ATTACH... SCREEN MESSAGES DURING BROKER SWITCHOVER
- 33710568;19.14 DBVM PROVISION DCS-10001 FAILED TO CREATE THE DATABASE PRCZ-4001 PRCZ-2103 [FATAL] ERROR IN PROCESS ?/BIN/ORAPWD
- 33657803;MERGE ON DATABASE RU 19.14.0.0.0 OF 33314523 33548869
- 32984625;RANDOM AFD DISK MISSING AFTER A NODE REBOOT IN SIHA.
- 33531364;LNX64-1913-CMT ASMCMD SHOULD SHOW ERROR MESSAGE ON FAILURES
- 33312823;LNX64-1912-CMT LOTS OF KJOER_OS_GETNEXT FAILED MESSAGES FLOODING IN GEN0 TRACE AND UNPUBLISH FENCED ORPHAN MSG IN ASM ALERT LOG
- 33695048;LOG4J 2.17 CPU FIX FOR CVE-2021-45105 FOR SPATIAL CLIENT SIDE JARS
- 31335037; RDBMS - DSTV35 UPDATE - TZDATA2020A
- 30432118;MERGE REQUEST ON TOP OF 19.0.0.0.0 FOR BUGS 28852325 29997937
- 33561310;OJVM RELEASE UPDATE: 19.14.0.0.220118 (33561310)
- 31732095;UPDATE PERL IN 19C DATABASE ORACLE HOME TO V5.32
- 33497160;JDK BUNDLE PATCH 19.0.0.0.220118
- 33837519;OCW Interim patch for 33837519
- 33515361;Database Release Update : 19.14.0.0.220118 (33515361)
It is important to highlight that the environment is in the multitenant model, and we have a pdb in the environment
What is the problem?
a) When executed directly from SQL Server Management Studio, the procedure works without problems
b) When executed within a Delphi 2010 application, through an ADO connection, it throws the following error:
Cannot start a transaction for OLE DB provider "OraOLEDB.Oracle" for linked server "XX"
IMPORTANT: The error is the same when using TADOQuery or TADOStoredProcedure.
Would anyone have any clues?
SETinstead ofSELECTwhen you assign@lksrv.EXECing it. I'd be curious to know what's in@lksrv, for example... does it contain the name of a linked server with a dot.already appended? Do your queries actually containand WHEREandand INNER JOIN?