Forum Discussion

Stefanssce's avatar
Stefanssce
Copper Contributor
Sep 12, 2023

SQL Server 2022 create external data source with Oracle TNS files (introduced with CU2)

Hi,

I am trying to set up an external data source to connect to Oracle. This works fine when I specify the Oracle hostname like "LOCATION = 'oracle://oracle1:1521".

In our setup we normally us TNS where there are two servers specified. oracle1 and oracle2. In case of a failover the connection uses the server which is online. In the working example above I cannot use of this option and the external table will fail if the database is running on oracle2.

I can read in the documentation that with CU2 in SQL 2022 there was an option introduced to use TNS and I hope this will solve this problem. However, the documentation is vague about how to use it and I do not find other documentation about the "feature".

Could anyone give an example how to use this option to be able to use the "Oracle" failover option?

Thanks.
Stefan

  • After a lot of try and error I managed to get it working. Here the example which might help others:

    --SQL
    CREATE EXTERNAL DATA SOURCE OracleSource
    WITH ( LOCATION = 'oracle://ORA_TEST' , connection_options = 'ServerName=ORA_TEST;TNSNamesFile=C:\ORA\TNS_ADMIN\tnsnames.ora',
    PUSHDOWN = ON,
    CREDENTIAL = cred_oracle)

    --TNSNAMES.ORA which is store in C:\ORA\TNS_ADMIN

    ORA_TEST =
    (DESCRIPTION =
    (CONNECT_TIMEOUT = 3)
    (ENABLE = BROKEN)
    (ADDRESS = (PROTOCOL = TCP)(HOST = oracle1.yourdomain.net )(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = oracle2.yourdomain.net )(PORT = 1521))
    (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = ORA_TEST)
    )
    )



  • Stefanssce's avatar
    Stefanssce
    Copper Contributor
    After a lot of try and error I managed to get it working. Here the example which might help others:

    --SQL
    CREATE EXTERNAL DATA SOURCE OracleSource
    WITH ( LOCATION = 'oracle://ORA_TEST' , connection_options = 'ServerName=ORA_TEST;TNSNamesFile=C:\ORA\TNS_ADMIN\tnsnames.ora',
    PUSHDOWN = ON,
    CREDENTIAL = cred_oracle)

    --TNSNAMES.ORA which is store in C:\ORA\TNS_ADMIN

    ORA_TEST =
    (DESCRIPTION =
    (CONNECT_TIMEOUT = 3)
    (ENABLE = BROKEN)
    (ADDRESS = (PROTOCOL = TCP)(HOST = oracle1.yourdomain.net )(PORT = 1521))
    (ADDRESS = (PROTOCOL = TCP)(HOST = oracle2.yourdomain.net )(PORT = 1521))
    (CONNECT_DATA =
    (SERVER = DEDICATED)
    (SERVICE_NAME = ORA_TEST)
    )
    )



Resources