how connect oracle database with ms sql server · pdf filenow you can configure this dg4odbc...
TRANSCRIPT
How connect Oracle Database with Ms SQL Server Database
By shoaib
Here I have Install MS SQL Server 2005 (32- Bit) On Windows server 2003 R2
(64 Bit)
So we install DG4ODBC driver (64 Bit) on Server where we install MS SQL
server database. Because Windows operating system its 64 bit so
Here you only select this Oracle Database Gateway for ODBC 11.2.0.4.0
from Components and click on Next Tab
During Listener Configuration if it’s give error like this so use another port
number here we use 1533 port number
Just click on No
After DG4ODBC driver install now configure this steps on windows where you
install MS SQL SERVER 2005
Go to Start > Control Panel > Administrative Tools > Data Sources (ODBC)
Create a New Data Source to SQL Server page open
Here give any name in this What name do you want to use to refer to the data
source ?
Here we give testmssql in name tab
After that in How do you want to describe the data source ? give any thing
Here we give in Description tab we type testmssql
And in Which SQL Server do you want to connect to ? tab give your host name
where you install Ms Sql server 2005 here my host name its tmssql so I give
tmssql in Server tab
Then click on next
Here select this With SQL Server authentication using a login ID and password
entered by the user
And select this connect to SQL Server to obtain default setting for the additional
configuration options and enter SA user and its password in password tab
Select this Change the default database to and here you select your ms sql server
database name you want to connect here TEST1 its my ms sql server database
name and click on next tab
Now you can configure this dg4odbc driver for oracle database using this steps
Go to your dg4odbc home where you install
Here I install on E drive go to hs folder and open this admin folder
E:\product\11.2.0\tg_1\hs\admin
Here create this init<sid>.ora file.
You can give any name at sid. Old drive before create init file
Here we create new init file.
Into this initmssql.ora file look like this
Here at this HS_FDS_CONNECT_INFO give name as you mention in your
System DSN and HS_FDS_TRACE_LEVEL also Off
Same of this init.ora file its look like below
# This is a sample agent init file that contains the HS parameters that are
# needed for the Database Gateway for ODBC
#
# HS init parameters
#
HS_FDS_CONNECT_INFO = testmssql
HS_FDS_TRACE_LEVEL = OFF
#
# Environment variables required for the non-Oracle system
#
#set <envvar>=<value>
After creating initmssql.ora file into this admin folder its look like below
Now also change into your listener file in your DG4ODBC driver home and
open network and open admin folder put enter into your listener.ora file
Open this E:\product\11.2.0\tg_1\NETWORK\ADMIN
Here in this listener.ora file put your sid_name as you mention in this
init<sid>.ora file this sid name put here at this sid_name and also put this line
into this listener.ora file
ENVS =
"EXTPROC_DLLS=ONLY:E:\product\11.2.0\tg_1\bin\oraclsra11.dll"
# listener.ora Network Configuration File: E:\product\11.2.0\tg_1\network\admin\listener.ora
# Generated by Oracle configuration tools.
#LISTENER =
# (DESCRIPTION_LIST =
# (DESCRIPTION =
# (ADDRESS = (PROTOCOL = TCP)(HOST = tmssql)(PORT = 1533))
# (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1533))
# )
# )
LISTENER =
(DESCRIPTION_LIST =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1533))
)
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = tmssql)(PORT = 1533))
)
)
SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME = mssql)
(ORACLE_HOME = E:\product\11.2.0\tg_1)
(PROGRAM = dg4odbc)
(ENVS = "EXTPROC_DLLS=ONLY:E:\product\11.2.0\tg_1\bin\oraclsra11.dll")
)
)
ADR_BASE_LISTENER = E:\product\11.2.0\tg_1
Now on Ms SQL Server we successfully configure this DG4ODBC driver.
Now we create Service for Ms SQL server and DB Link on Oracle RAC database.
Here we install Oracle 10g Rac database on another server its oracle 10g
rac database ( 64 Bit ) and Operating system its Windows server 2008
Enterprise Edition Service Pack 2 (64 Bit)
Now on Oracle server edit your tnsnames.ora file
You can find tnsnames.ora file at this location OracleHome/Network/admin
My file here at this location
C:\oracle\product\10.2.0\db_1\NETWORK\ADMIN
You can write this line into your tnsname.ora file
MSSQL = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = tmssql)(PORT = 1533)) ) (CONNECT_DATA = (SERVICE_NAME = mssql)
) (HS = OK) )
Here this description of this service
MSSQL – it’s a service name you can write any name as you want as a
service name to connect with MS Sql Server
HOST = tmssql – Host name of where you install Ms Sql Server.
SERVICE_NAME = mssql – here you mention sid name you define on
Ms sql server init<sid>.ora and also in listener file at Ms Sql server sid
name.
HS= OK – You mention this
After creating service on oracle RAC server we tested it using tnsping to this
Ms Sql service we created before
Now after successfully created service for MS SQL Server database on Oracle
first node we create db link to connect with MS SQL Server database
SQL> create database link con_mssql connect to "sa" identified by "oracle" using
'mssql';
In this link
con_mssql -- it’s a link name you can give any name here you want
here we give con_mssql as a db link name
connect to "sa" identified by "oracle" --- here “sa” it’s a Ms SQL
database user with whom you want to connect to and give this “sa” user
password also
'mssql' -- mssql it’s a service name which we create before using this
service we can connect oracle database with ms sql server database
Now you can check this link successfully created
Now you can insert data into ms sql server using this db link from oracle
to ms sql server
Before inserting row check table no any row into this emp table
Insert row from oracle to ms sql server using db link
After inserting row you can check data into your ms sql server database
row is successfully inserted
You can perform select query using this syntax also from oracle database
Now if you have more than one MS SQL Server
database and you want to connect with this database
from oracle to ms sql server database.
For this purpose here we create one more database at ms sql server site
For this task again we have to put entry of this test2 database in ODBC
using below task
Go to Control Panel > Administrative Tools > Data Sources (ODBC)
And click on System DSN and Click on Add tab
Create a New Data Source to SQL Server page open
Here give any name in this What name do you want to use to refer to the data
source ?
Here we give test2mssql in name tab
After that in How do you want to describe the data source ? give any thing
Here we give in Description tab we type tes2tmssql
And in Which SQL Server do you want to connect to ? tab give your host name
where you install Ms Sql server 2005 here my host name its tmssql so I give
tmssql in Server tab
Then click on next
After add this database in ODBC now we have to create new init.ora file on ms
sql server database
For that go to your DG4ODBC driver home \ hs\admin
Here my path its “E:\product\11.2.0\tg_1\hs\admin”
Go to this path and create new init.ora file just copy and past your existing
init.ora file and rename it.
Init<sid>.ora file here we create in this sid you can give any name for sid.
Here we create new init file for this new database its name “ initmssqln.ora ”
Now in this initmssqln.ora file give your new ms sql server database name you
mention in this ODBC System DSN
At this HS_FDS_CONNECT_INFO parameter
After that put entry of this your new ms sql server information into your
listener.ora file on ms sql server computer where you install dg4odbc driver
Go to E:\product\11.2.0\tg_1\NETWORK\ADMIN and open this listener.ora
file
And put this entry into your listener.ora file
(SID_DESC =
(SID_NAME = mssqln)
(ORACLE_HOME = E:\product\11.2.0\tg_1)
(PROGRAM = dg4odbc)
(ENVS =
"EXTPROC_DLLS=ONLY:E:\product\11.2.0\tg_1\bin\oraclsra11.dll")
)
Here this sid_name its name you mention in your init<sid>.ora name. as sid
name
After editing in listener.ora file restart the listener. If its stuck while
restarting you can manually restart its service from service.msc restart its
listener service from there
Now after that create new service for this new database on oracle rac server on
first node.
Put entry in your tnsnames.ora file on oracle RAC server first node for this your
new service for ms sql server.
Open this your tnsnames.ora from this location
C:\oracle\product\10.2.0\db_1\NETWORK
NWMSSQL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = tmssql)(PORT = 1533))
)
(CONNECT_DATA =
(SERVICE_NAME = mssqln)
)
(HS = OK)
)
NWMSSQL – it’s a service name
SERVICE_NAME = mssqln – its name we provide in init<sid>.ora. this
mssqln its sid name we mention there in init<sid>.ora file.
After successfully create service for ms sql server on oracle database we
can check it using tnsping to this nwmssql service we create for ms sql
server
After successfully configure this new service for new ms sql server
database we create new db link for this new ms sql server database using
this
In this create database link
con_newms -- it’s a database link name with this link we can connect
oracle database to ms sql server database
"sa" identified by "oracle" – it’s a ms sql server database user and its
password
Nwmssql – its s service name we create using this service name we can
connect oracle database to ms sql server database.
We can check this this link is successfully configured.
If you want to use this db link on your another node on RAC database
Here after created db link on first node you cannot use this db link on your
another node on rac database. If you want to use this db link on your another
node you have to create service on your another node to connect your oracle
database with MS SQL Server.
SQL> create database link con_newms connect to "sa" identified by "oracle" using
'nwmssql';
Just open your tnsnames.ora file from your another node and put entry same as
you mention on your first node.
Node1 tnsnames.ora file
Now open your tnsnames.ora file on your second node and past this MS SQL
Server service info in this tnsnames.ora file
******** MS SQL SERVER 2005 SERVICES ************
MSSQL =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = tmssql)(PORT = 1533))
)
(CONNECT_DATA =
(SERVICE_NAME = mssql)
)
(HS = OK)
)