Search code examples
sql-serverhanaexternal-tables

Sql Server 2019 External Table to SAP HANA ignoring Schema in Location clause


I'm looking for a better way to bring in data from Hana into our Sql Server EDW. Currently we're using OpenQuery but I really want to get to using Sql Server's External Tables functionality because then I can easily push much of the compute requirements down to Hana without needing to create complication query strings.

However, my first attempt proved frustrating as something is apparently deciding to always use my default schema and not the one I presented.

This is the test code I'm using to pull back SAPABAP1.TCURR from one of our Hana instances (certain details obscured for the usual reasons):

If Object_Id('SAP.TCURR') Is Not Null
    Drop External Table SAP.TCURR;
Go
If Exists (Select 1 From sys.external_data_sources Where name = 'SAPHANA_HNQ')
    Drop External Data Source SAPHANA_HNQ;
Go
If Exists (Select 1 From sys.database_credentials Where name = 'Me@Hana')
    Drop Database Scoped Credential Me@Hana;
Go
Create Database Scoped Credential Me@Hana With
     Identity = 'rambler'
    ,Secret = '**SuperSecretSquirrelPassword**';
Go
Create External Data Source SAPHANA_HNQ With
    (
         Location ='ODBC://10.10.10.10:30015'
        ,Credential = Me@HANA
        ,Pushdown = On
        ,Connection_Options = 'Driver={HDBODBC};ServerNode=10.10.10.10:30015'
    );
Go
Create External Table SAP.TCURR
    (
         MANDT NVarChar(3)      Not Null
        ,KURST NVarChar(4)      Not Null
        ,FCURR NVarChar(5)      Not Null
        ,TCURR NVarChar(5)      Not Null
        ,GDATU NVarChar(8)      Not Null
        ,UKURS Numeric(9, 5)    Not Null
        ,FFACT Numeric(9, 0)    Not Null
        ,TFACT Numeric(9, 0)    Not Null
    ) With
    (
         Data_Source = SAPHANA_HNQ
        ,Location = '"SAPABAP1"."TCURR"'
    );

Go
Select   *
  From   SAP.TCURR;

However, when I execute this, I get the following error:

Msg 7320, Level 16, State 110, Line 28
Cannot execute the query "Remote Query" against OLE DB provider "MSOLEDBSQL" for linked server "(null)". 105082;Generic ODBC error: [SAP AG][LIBODBCHDB DLL][HDBODBC] Base table or view not found;259 invalid table name:  Could not find table/view TCURR in schema RAMBLER: line 1 col 77 (at pos 76) .

What am I doing wrong here that's making the driver want to use my schema rambler and not the one I gave it SAPABAP1? I also tried defining the Location as just SAPABAP1.TCURR, but that made zero difference.

For the record, the following OpenQuery returns data back just fine:

Select * From OpenQuery(SAPHANA_HNQ, 'Select * From "SAPABAP1"."TCURR"');

Sql Server 2019 RTM


Solution

  • These worked for me

    Location = '.SAPABAP1.TCURR'