Connect MS SQL Server database to Oracle 11g datab

2020-07-18 12:09发布

问题:

I am struggling to create a db link from a Oracle Database to one SQL Server.

For that, I have added the followings:

In file tnsnames.ora:

sqlUserConn =
  (DESCRIPTION=
    (ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))
      (CONNECT_DATA=(SID=sqlUserConn))
      (HS=OK)
    )

in file listener.ora:

(SID_DESC=
  (SID_NAME=sqlUserConn)
  (ORACLE_HOME=C:\oraclexe\app\oracle\product\11.2.0\server)
  (PROGRAM=dg4odbc)
)

in file sqlnet.ora:

SQLNET.AUTHENTICATION_SERVICES = (NTS)
NAMES.DIRECTORY_PATH= (TNSNAMES, ONAMES, HOSTNAME) 

in file initsqlUserConn.ora:

HS_FDS_CONNECT_INFO = sqlUserConn
HS_FDS_TRACE_LEVEL = OFF

The files tnsnames.ora, sqlnet.ora and listener.ora are placed in **server\network\admin** and initsqlUserConn.ora is placed in **server\hs\admin**

I have the following sql statement:

CREATE DATABASE LINK sqlUserConn CONNECT TO "USER" IDENTIFIED BY "PASSWORD" USING 'sqlUserConn';

And then to test the db link, I am running something similar to:

Select * from table@sqlUserConn

This command is firing the following error:

ORA-12154: TNS:could not resolve the connect identifier specified

Obviously, I have done something wrong.. but still I don't get it.. It should work as I have seen a lot of users doing it like this

Could someone point me to the correct solution for linking a SQL Server database to Oracle 11g?

回答1:

First of all, make sure you are using the correct DSN architecture (32 or 64 bits). It will fire errors if using incorrect architecture. Oracle on Windows has a strange behavior, therefor the command lsnrctl reload or even using lsnrctl stop and then lsnrctl start wont help in refreshing the info placed in the files specified (tnsnames, listener, etc..). So the only solution is to reboot and then check if dblink works.