Steps to create database link between Oracle database and SQL Server

 Creating a database link between SQL Server and Oracle allows seamless data exchange between the two systems. Here’s a step-by-step guide:


Step 1: Install the Required Drivers

Install Oracle Database Gateway for SQL Server (ODG4MS). This acts as a bridge between Oracle and SQL Server.

Ensure the Oracle Client is installed on the Oracle database server or the server acting as the gateway.

Step 2: Configure the Oracle Database Gateway

Locate Configuration Files:


Navigate to the $ORACLE_HOME/network/admin directory on the Oracle Gateway server.

Edit tnsnames.ora: Add an entry for the database link pointing to the SQL Server database:



dg4msql =

  (DESCRIPTION =

    (ADDRESS = (PROTOCOL = TCP)(HOST = <SQL_SERVER_HOSTNAME>)(PORT = 1521))

    (CONNECT_DATA = (SID = dg4msql))

    (HS=OK)  -- Required for heterogeneous services

  )

 

Edit listener.ora: Update the Oracle listener configuration to recognize the gateway:



SID_LIST_LISTENER =

  (SID_LIST =

    (SID_DESC =

      (SID_NAME = dg4msql)

      (ORACLE_HOME = <path_to_oracle_home>)

      (PROGRAM = dg4msql)

    )

  )

  

Restart the Oracle Listener:



lsnrctl stop

lsnrctl start

Step 3: Test Connectivity to SQL Server

Use tnsping to verify the connection to the SQL Server database via the gateway:



tnsping dg4msql

Step 4: Create the Database Link in Oracle

Login to the Oracle Database:



sqlplus / as sysdba

Create the Database Link: Replace placeholders with actual values:



CREATE DATABASE LINK sqlserver_link

CONNECT TO "<sql_user>" IDENTIFIED BY "<sql_password>"

USING 'dg4msql';

Test the Database Link:



SELECT * FROM dual@sqlserver_link;

Step 5: Validate and Troubleshoot

If you encounter issues:

Check the Oracle listener log for errors.

Ensure the Oracle Gateway services are running.

Verify the SQL Server instance allows remote connections.

Test SQL Server connectivity using tools like SQLCMD or telnet.

Comments

Popular posts from this blog

Key points on Read-Only Instance and Read-Only Database

How to Configure Logging for EM 12c Management Agent