1

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.

  1. In our stored procedure, the name of the linked server is obtained dynamically, and access to Oracle is done within an EXEC

  2. The 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
    ');
  1. 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)
   ');
  1. 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?

4
  • 1
    Who knows, since you don't attach the code. Can you disable distributed transaction thing setting on the linked server? It should avoid the problem Commented May 15, 2023 at 12:56
  • Could this be caused by multiple result sets? Try a SET instead of SELECT when you assign @lksrv. Commented May 15, 2023 at 13:28
  • One of the easiest things you could do to debug this is to store your concatenated query into a local variable and print it out before 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 contain and WHERE and and INNER JOIN? Commented May 15, 2023 at 14:13
  • 1
    Many thanks for the suggestions. I clarify however that the code works perfectly via management studio, so I have no problems with punctuation or syntax. Yes, I already did a 'select' of the command that is executed, and the same thing happens for this command alone: via management studio everything OK, via ADO the same error. I think it's a dynamic issue, of context, associated with some limitation of ADO, or default configuration of ADO, but that's just a vague idea without foundation. Commented May 16, 2023 at 12:59

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.