1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Using Oracle Database Gateway to connect OCI Database system 19c and MS SQL Server 2016

Last updated at Posted at 2019-09-26

Background

Sometimes, we have heterogeneous database services in our system, we expect to transparently access data residing in a non-Oracle system from an Oracle environment. In this post, we will discuss how to use the Oracle Database Gateway to provide the ability to make this done.

Exactly speaking, we will install Oracle Database Gateway 19c on an OCI Database System 19c and make a connection to an existing Microsoft SQL Server 2016.

Prerequisites

Assuming we already have the following service/server.

  • OCI Database System 19c
    image.png

  • MS SQL Server 2016
    image.png

Setup VNC server in OCI Database System

Pre-check

We are going to use Oracle Universal Installer to install the Oracle Database Gateway into the OCI Database System, so we need to setup VNC server on the OCI Database System first.

Login to the OCI Database System with default opc user and check the Linux version.

image.png

Since the base image of OCI Database System 19c is Oracle Linux 7.5, and Server with GUI package is already installed. So we do not need to install it.

image.png

Configure VNC server

Switch to oracle user and setup password for the VNC server.

su - oracle
vncpasswd

image.png

Start the VNC server and check the port number which VNC server is using.

vncserver
vncserver -list
netstat -ltp4 | grep 590

image.png

Configure iptables and VCN security list

iptables

By default, VNC server port 590X is not allowed by the OCI Database System iptables, so we need to perform following commands to open the port 5901.

# check the iptables
iptables -L
# allow the inbound of port 5901
iptables -I INPUT 6 -p tcp -m state --state NEW -m tcp --dport 5901 -j ACCEPT

image.png

VCN Security List

We also need to ensure the port number 5901 is not blocked by the security list of the VCN(Virtual Cloud Network) which the OCI Database System resides in.

For simplicity, I allow all the ingress traffic to this VCN.
image.png

Connect from VNC Viewer

On your desktop, try to connect to the OCI Database System from the TigerVNC Viewer
image.png

Input the password and click OK
image.png

You should be able to see the OCI Database System terminal in the VNC Viewer as below.
image.png

Install Oracle Database Gateway

Download

You can download Oracle Database Gateway 19c from here.
https://www.oracle.com/database/technologies/oracle19c-linux-downloads.html
image.png

Then transfer the Oracle Database Gateway 19c installation package to the OCI Database System.
image.png

Install

Open VNC Viewer, move to where you placed the Oracle Database Gateway installation package and unzip it.

image.png

Go the unzipped directory gateway and execute the ./runInstaller file

image.png

Oracle Universal Installer interface will pop up and we can click Next to install gateway to the default Oracle home directory
image.png

Select Oralce Database Gateway for Microsoft SQL Server and click Next.
image.png

Now we need to input some critical information of the target SQL Server.

image.png

  • Host Name: public IP address of the SQL Server or the hostname
  • Port Number: 1433 is the default port number of SQL Server, if yours is using any other port, just change it
  • Server Name: the instance name of the SQL Server, you can get it from SQL Server Configuration Manager as shown below
  • Database Name: the database name you want to connect to

SQL Server instance name
image.png

Review the summary and click Install
image.png

Execute the script as root user
image.png

image.png

Once you executed the script, back to VNC Viewer and click OK, you will see the successful message.
image.png

Until now, the Oracle Database Gateway 19c is installed.

Configure the Oracle Database Gateway

Pre-check

Login to the OCI Database System and switch to oracle user.
Go to following directory and start to configure the Oracle Database Gateway.

# go to the directory
cd $ORACLE_HOME/dg4msql/admin
# have a look at the gateway initialization file
cat initdg4msql.ora

image.png

Everything looks good, all the required SQL Server information are reflected here.
Open file tnsnames.ora.sample and listener.ora.sample, we will use the contents to make the configuration.

Configure the tnsnames.ora

Make sure you are working as user oracle. Go to the directory $ORACLE_HOME/network/admin and update the tnsnames.ora file. Copy the content from tnsnames.ora.sample and paste it into tnsnames.ora, remember to change the HOST to be your hostanme.

image.png

Configure the listener.ora

OCI Database System is built as a single instance RAC, user grid is the owner of the listener, so we need to switch to user grid. Then copy the content(only the SID_LIST_LISTENER part) from listener.ora.sample and paste it into listener.ora.
Please check below screenshot.

# switch to user grid
sudo su - grid
# move to the listener directory
cd $ORACLE_HOME/network/admin
vim listener.ora

image.png

Reload the listeners and check the status. We can see that the listener dg4msql is registered and working well.

lsnrctl reload
lsnrctl status

image.png

Until now, the configuration of the Oracle Database Gateway to connect to a specific SQL Server is completed. Next, let's verify how it works.

Verify the Oracle Database Gateway

Login to the OCI Database System as user oracle and connect to the database as sys.

sudo su - oracle
sqlplus / as sysdba
-- change to pdb
alter session set container=pdb1;
-- create database link to the SQL Server
create public database link xucheng connect to "SQL_SERVER_USER" identified by "SQL_SERVER_PASSWORD" using 'dg4msql';
-- query table [trex] through the database link [xucheng]
select * from trex@xucheng;

The database link is created as an object in the database, so you can use it any time unless you drop it.
In the sample query above, trex is a table in SQL Server database xucheng. And the xucheng in the sample query is the database link we just created. We use this database link to connect to the database in SQL Server. So the basic usage is select * from <TARGET_TABLE_NAME>@<DB_LINK>

In OCI Database System the global_names parameter is set to TURE by default, so you will get the ORA-02085 error.
image.png

You can set the global_names to FALSE to overcome the ORA-02085 issue at session level, or you can also alter this parameter at the system level.

ALTER SESSION SET global_names = FALSE;
select * from trex@xucheng;

As you can see in below screenshot, we can get the same query result as in SQL Server.
image.png

Now, we can query the SQL Server database from OCI Database System 19c instance.

References

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?