Sunday, March 11, 2012

How to connect Oracle Database to Microsoft SQL Server by using Heterogeneous Services

In the name of Allah, the most Beneficial, the most Merciful

In this article i will be describing "How to connect Oracle Database to Microsoft SQL Server by using Heterogeneous Services". Access and other databases can also be connected by this method. First of all we need to create ODBC connection on oracle host machine. Go to "Control Panel" -> "Administrative Tools" -> "Data Sources (ODBC)" following screen will appear.

Figure - 1

Click on Add button.
 
Figure - 2

Select "SQL Server" and click Finish button.
 
Figure - 3

Name the Data Source and provide the Server information as shown above and click Next button.

Figure - 4

Provide login information and click Next button.
 
Figure - 5

Select the default database from list and click Next button.
 
Figure - 6

Optionally check the logging for query and statistics and click Finish button.

Figure - 7

Click the "Test Data Source" button.
 
Figure - 8

Click Ok button. Now create a init<ODBC>.ora file in ORACLE_HOME\hs\admin as follows.

Figure - 9

Add the SID_DESC in SID_LIST_LISTENER parameter in listener.ora file as shown in screen below.

Figure - 10

Now restart listener by "lsnrctl reload" command.

lsnrctl reload

Create a connection sting in tnsnames.ora file as shown in figure below.

Figure - 11

check the string by tnsping command

tnsping attendence

 Now create a database link for the Sql Server database as follows.

CREATE PUBLIC DATABASE LINK sqlsrv CONNECT TO "sa" IDENTIFIED BY "MyPassword" USING 'attendence';

Now query the table in SQL Server from oracle by following query.

SELECT "acol", "bcol"
FROM     atab@SQLSRV;


Insha-Allah this will help and serve the purpose. For any corrections and improvements please suggest.


4 comments:

  1. Nasir sb good work, keep it up. Heterogeneous connection to ORACLE on non-Window environment is a challenge, need to focus on that as well.

    ReplyDelete
    Replies
    1. Aslam o Alikum,
      Thanks for your comment. Out database server in on windows at the moment and we are trying to shift it to Solaris. After that we will on non-Window environment.
      Allah Hafiz

      Delete
  2. Thanks a lot for your explanation , it's very useful.

    Regards

    ReplyDelete
  3. Thank you very much brother it helps me to configure DB2, it is not ok now but the process you describe is OK.

    ReplyDelete