Creating a database link from oracle to oracle database is easy. But setting up db_link from oracle to mssql server isn’t straight forward. We need to do odbc setup. Its knows as heterogeneous db_link. We can achive this either by using third party odbc drivers or using oracle provided gateways utility.
Here in this article i will show how to create db_link using oracle gateway.
Download the gateway file from OTN.
unzip the file in oracle database server and execute runInstaller
[oracle@localhost HouseKeeping]$ pwd /u01/home/oracle/HouseKeeping [oracle@localhost HouseKeeping]$ unzip p13390677_112040_Linux-x86-64_5of7.zip [oracle@localhost HouseKeeping]$ cd gateways [oracle@localhost gateways]$ ls -ltr total 56 drwxr-xr-x 4 oracle oinstall 4096 Aug 26 2013 install drwxr-xr-x 4 oracle oinstall 4096 Aug 26 2013 legacy -rwxr-xr-x 1 oracle oinstall 3267 Aug 26 2013 runInstaller drwxr-xr-x 2 oracle oinstall 4096 Aug 26 2013 response drwxr-xr-x 14 oracle oinstall 4096 Aug 26 2013 stage -rw-r--r-- 1 oracle oinstall 30016 Aug 27 2013 readme.html -rw-r--r-- 1 oracle oinstall 500 Aug 27 2013 welcome.html ./runInstaller
Select the oracle_home same as that of the oracle database.
Here we are connecting to microsoft sql server. So select that sql server gateway option.
Enter the sql server details to which we are creating the database link.
Run the root.sh file from root user . Now the gateway installation is done.
Now add the below entry in listener.ora file and start the listener
( HOST=13.129.101.40)(PORT=1521) — This is the oracle database server ip
LISTENER_dg4mssql= (DESCRIPTION_LIST= (DESCRIPTION= (ADDRESS_LIST= (ADDRESS=(PROTOCOL=TCP)(HOST=13.129.101.40)(PORT=1521)) ) ) ) SID_LIST_LISTENER_dg4mssql= (sid_list= (sid_desc= (sid_name=dg4msql) (ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1) (program=dg4msql) (envs="LD_LIBRARY_PATH=/app/oracle/product/11.2.0/db_1/dg4msql/driver/lib:/app/oracle/product/11.2.0/db_1/lib") ) ) lsnrctl start LISTENER_dg4mssql
Now add the tns entry in tnsnames.ora file
dg4msql = (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=13.129.101.40)(PORT=1521)) (CONNECT_DATA=(SID=dg4msql)) (HS=OK) ) [oracle@localhost admin]$ tnsping dg4msql TNS Ping Utility for Linux: Version 11.2.0.4.0 - Production on 15-JUL-2015 07:24:06 Copyright (c) 1997, 2013, Oracle. All rights reserved. Used parameter files: /u01/app/oracle/product/11.2.0/db_1/network/admin/sqlnet.ora Used TNSNAMES adapter to resolve the alias Attempting to contact (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=13.129.101.40)(PORT=1521)) (CONNECT_DATA=(SID=dg4msql)) (HS=OK)) OK (10 msec)
Lets create the database link and test it.
SQL> Create public database link MSTEST connect to MSTEST identified by mstest124 using 'dg4msql'; Database link created. SQL> select count(*) from "INFORMATION_SCHEMA"."TABLES"@MSTEST; 2 rows selected
please explain is it database server IP
13.129.101.40
Yes dear
hi
you have mentioned below IP address, by looking at port, it looks like you have mentioned oracle server, please clear do we need to mention oracle server IP and Port from where we are trying to connect to SQL server or do we have to mention SQL server IP and PORT in both listener.ora and tnsmaes.ora file
HOST=13.129.101.40)(PORT=1521)
2nd question,
while creating link with your mentioned query, link name is missing, am i right? username MSTEST and password, are these username of SQL Server
Create public database link connect to MSTEST identified by mstest using ‘dg4msql’;
Hi Kashif,
Yes ( HOST=13.129.101.40)(PORT=1521) — This is the oracle database server ip .
Regarding 2nd question, Yes I have missed the db_link name. Thanks for pointing out the mistake. I have modified the same.
Regards
dbaclass admin
Thanks for a very quick reply. I wasn’t expected it so fast
i have followed your instruction. below is my Listener.ora, i made only one change, in SID_LIST_LISTENER_dg4mssql, i put /u01 before /app as thats my path
LISTENER_dg4mssql=
(DESCRIPTION_LIST=
(DESCRIPTION=
(ADDRESS_LIST=
(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.8.6)(PORT=1521))
)
SID_LIST_LISTENER_dg4mssql=
(sid_list=
(sid_desc=
(sid_name=dg4msql)
(ORACLE_HOME=/u01/app/oracle/product/11.2.0/db_1)
(program=dg4msql)
(envs=”LD_LIBRARY_PATH=/u01/app/oracle/product/11.2.0/db_1/dg4msql/driver/lib:/u01/app/oracle/product/11.2.0/db_1/lib”)
)
)
lsnrctl start LISTENER_dg4mssql ……..this commands runs successfully
this is my tnsnames.ora
dg4msql =
(DESCRIPTION=
(ADDRESS=(PROTOCOL=tcp)(HOST=192.168.8.6)(PORT=1521))
(CONNECT_DATA=(SID=dg4msql))
(HS=OK)
below is the output of tnsping
tnsping dg4msql
TNS Ping Utility for Linux: Version 11.2.0.4.0 – Production on 08-MAR-2017 13:49:32
Copyright (c) 1997, 2013, Oracle. All rights reserved.
Used parameter files:
/u01/app/oracle/product/11.2.0/db_1/network/admin/sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION= (ADDRESS=(PROTOCOL=tcp)(HOST=192.168.8.6)(PORT=1521)) (CONNECT_DATA=(SID=dg4msql)) (HS=OK))
OK (0 msec)
but when i tried to connect with SQL Server, i got below error
ERROR at line 1:
ORA-28545: error diagnosed by Net8 when connecting to an agent
Unable to retrieve text of NETWORK/NCR message 65535
ORA-02063: preceding 2 lines from MSTEST
could you please help me about. one thing which is confusing, you havent mentioned SQL Server username/password anywhere in your above article, how it’ll be authenticated by SQL Server?
Hi,
Please send the database link creation command.
Here MSTEST is the username in sqlserver database and mstest124 is the password.
Create public database link MSTEST connect to MSTEST identified by mstest124 using ‘dg4msql’;
Database link created.
Regards
DBACLASS Admin
Also,
Please check the listener.ora log and
try to give the complete patch (PROGRAM=/u01/OracleGateways/bin/dg4msql)
Regards
DBACLAS ADMIN
I am aslo facing this error ,Can you please help me with it
does it require separate third party odbc driver installed on top of oracle database gateway for sql sever.
No dear, no need of any third party drivers. Just oracle gateway software is suffice.
That was very helpful
Do we need to install Oracle Gateway on Database sever ? or application server ?
also, how to know if Oracle Gateway is already configured
You need to install oracle gateway on the database server
Hi
In this can we create multiple db links from oracle to SQL server using oracle gateway.
Yes you can create multiple db links .
Hi,
If we need access oracle db from sql server via db link then the same oracle gateway can be used or any change in above steps.
Hi ,
I am getting the below error while connecting to DB link.
SQL> SELECT * FROM PS_NAMES@***.****.net;
SELECT * FROM PS_NAMES@*****.*****.net
*
ERROR at line 1:
ORA-28545: error diagnosed by Net8 when connecting to an agent
Unable to retrieve text of NETWORK/NCR message 65535
ORA-02063: preceding 2 lines from ******************
Thanks,
can u share the listener.ora and tns ora details
Are the Above issue been Resolved, I have a Task to Create the DB link from 12c DB Solaris system to SQL Server.
Hello
I m getting below error after creating DB link
++++++++++++++
ERROR at line 1:
ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
[Oracle][ODBC SQL Server Wire Protocol driver]Connection refused. Verify Host
Name and Port Number. {08001}
ORA-02063: preceding 2 lines from ORACLE2MSSQL
Please suggest.