Skip to content

Fatih Acar's blog

About of Database Systems and Information Technologies

Menu
  • Home
  • About Me
  • Contact Me
Menu

Oracle DbLink With Odbc Connection From Oracle to MsSQL Server With FreeTDS

Posted on 18/04/201303/10/2019 by Fatih Acar

I will use Oracle 11g R2 database and SQL Server 2008 R2 on this example. If you want to connect from Oracle to SQL Server, you can use freeTDS connection library on Oracle Linux systems. If we use Windows Server for Oracle database, we can use direct Windows ODBC Driver Manager. On the other hand, we need some requirement for odbc connection on Linux System. FreeTDS is a odbc connection library for MsSQL Server and other database systems.

I made test below systems.

Systems

  • Oracle Linux 6.x / 7.x
  • Oracle 11g / 12c
  • Windows Server 2008 R2
  • MsSQL Server 2008 R2

dblink

Steps;

  • Download freetds-stable program
  • Install unixODBC and unixODBC-devel
  • Install freetds
  • Configure freetds.conf
  • Configure odbc.ini
  • Configure init
  • Configure Listener
  • Configure tnsnames
  • Create DbLink

Download freetds-stable

Download Page, Direct Download

Install unixODBC-devel

yum install unixODBC
yum install unixODBC-devel

Install Development Tools

yum groupinstall “Development Tools”

Install freeTDS

tar zfvx freetds-stable.tgz
cd freetds-0.91
./configure –prefix=/usr/local/freetds –with-tdsver=8.0 –enable-msdblib –with-gnu-ld
make
make install


Configure freetds.conf

vi /usr/local/freetds/etc/freetds.conf

[SQLSERVERADDRESS]

host = 192.168.10.10 # MsSQL Server IP Address
port = 1433 # MsSQL Server Port
tds version = 8.0 # Tds version for SQL Server 2008
client charset = ISO-8859-9 # For support of Turkish characters

Configure odbc.ini

vi /etc/odbc.ini

[SQLDSN]
Description = SQLDSN CONNECTION
Driver = /usr/local/freetds/lib/libtdsodbc.so
Servername = SQLSERVERADDRESS
Database = DBNAME

[ODBC Data Sources]
SQLDSN=FreeTDS

Configure init

vi $ORACLE_HOME/hs/admin/initSQLDB.ora

HS_FDS_CONNECT_INFO = SQLDSN
HS_FDS_TRACE_LEVEL = 0
HS_FDS_SHAREABLE_NAME = /usr/lib64/libodbc.so
HS_LANGUAGE = AMERICAN_AMERICA.WE8ISO8859P9
set ODBCINI=/etc/odbc.ini

Configure Listener

vi $ORACLE_HOME/network/admin/listener.ora

If you are using grid infrastructure, you have to edit grid’s listener in grid home.
Add below lines.

SID_LIST_LISTENER =
(SID_LIST =
(SID_DESC =
(SID_NAME=SQLDB)
(ORACLE_HOME=$ORACLE_HOME)
(PROGRAM=dg4odbc)
(ENVS= LD_LIBRARY_PATH=/usr/lib64:/usr/local/freetds/lib:$ORACLE_HOME/lib)
)
)

Configure tnsnames

vi $ORACLE_HOME/network/admin/tnsnames.ora

Add below lines.

SQLDB =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SID = SQLDB)
)
(HS = OK)
)

Create DbLink

SQL> CREATE DATABASE LINK DBLINKNAME CONNECT TO “SQLSERVERUSERNAME” IDENTIFIED BY “PASSWORD” USING ‘SQLDB’;

Share this:

  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook

5 thoughts on “Oracle DbLink With Odbc Connection From Oracle to MsSQL Server With FreeTDS”

  1. Krishna says:
    21/04/2014 at 08:29

    Hello

    We are seeing below error message when we try to connect using the new dblink.

    ————————————————————————————————————
    SQL> select COUNT(*) from dbo.SP_MASTER_ELECT_LOCK@TEST2SQLDEV;
    select COUNT(*) from dbo.SP_MASTER_ELECT_LOCK@TEST2SQLDEV
    *
    ERROR at line 1:
    ORA-28500: connection from ORACLE to a non-Oracle system returned this message:
    ORA-02063: preceding line from TEST2SQLDEV
    ————————————————————————————————————

    Please advice how to proceed.

    Regards,
    Krishna

    Reply
    1. Bora Aydemir says:
      29/05/2015 at 19:30

      I had the same problem, adding
      TDS_Version = 8.0
      to odbcinst.ini
      and
      HS_LANGUAGE=AMERICAN_AMERICA.WE8ISO8859P1
      to initSQLDB.ora
      solved my problem.

      Reply
  2. Bora Aydemir says:
    29/05/2015 at 19:26

    Shouldn’t the filename at “Configure init” be initSQLDB.ora instead of initSQLDB.ini?

    Reply
  3. Manoj says:
    28/11/2015 at 07:48

    Hi, i tried with the above steps but it is not connecting, it gives error of charset…

    in this example char set is of turkish, what will be the char set to connect default oracle or SQLserver.

    do you have solution to the above configuration if this gives error?.

    Regards
    Manoj

    Reply
  4. Linda says:
    07/05/2018 at 23:58

    using FreeTDS, with following odbc.ini file, I can connect to the ‘biostorage’ sql server database, but not the ahs_iamge data source. I always run into the following error when testing tsql connection. ‘Biostorage’ is SQL Sever 2012, “image_ahs’ is SQL server 2008. Any help would be appreciated.

    Thanks in advance!

    Linda

    oracle[]$ tsql -S xxxx -D RSHARE010T -U xxxx-P xxxx
    locale is “en_US.UTF-8”
    locale charset is “UTF-8”
    using default charset “UTF-8”
    Default database being set to RSHARE010T
    Error 20009 (severity 9):
    Unable to connect: Adaptive Server is unavailable or does not exist
    OS error 111, “Connection refused”
    There was a problem connecting to the server

    [Data Sources]
    biostorage = TDS connection

    [ODBC]
    Trace = 255

    [biostorage]
    Description = Biostorage SQL Server
    Driver = /usr/lib64/libtdsodbc.so.0
    Setup = /usr/lib64/libtdsS.so
    #Setup = /usr/local/lib/libtdsS.so
    Trace = No
    Database = bst_amgen_interface
    Server = x.x.x.x
    Port = 1433
    TDS_Version = 8.0
    # Convert UCS-2 encoded Unicode data to UTF-8
    ConvToUtf = Yes
    # Also do this conversion for data passed to Unicode ODBC function (SQLxxxW) calls
    ConvWToUtf = Yes
    VarMaxAsLong = Yes

    [image_ahs]
    Description = IMAGE data SQL Server
    Driver = /usr/lib64/libtdsodbc.so.0
    Setup = /usr/lib64/libtdsS.so
    #Setup = /usr/local/lib/libtdsS.so
    Trace = No
    Database = Apercio_Spectrum
    Server = x.x.x.x
    Port = 49230
    TDS_Version = 8.0

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.



View Fatih ACAR's profile on LinkedIn

Categories

  • Databases (329)
    • MsSQL Server (18)
      • Administration (16)
      • Errors and Solutions (4)
      • SQL (2)
    • MySQL (5)
      • Administration (4)
      • Backup And Recovery (1)
      • Errors and Solutions (1)
    • Oracle (290)
      • Administration (79)
      • Backup And Recovery (29)
      • Errors and Solutions (195)
      • Procedure (10)
      • SQL (32)
    • PostgreSQL (16)
      • Administration (15)
      • Errors and Solutions (3)
      • SQL (2)
    • Redis (1)
  • Microsotf Dynamics CRM (1)
  • Operating Systems (47)
    • Linux & Unix (34)
    • Windows (13)
  • Programing (5)
    • Python (5)
  • SAP (15)
    • Errors and Solutions (4)
    • SAP Basis (12)
  • Security (8)
    • Database Security (6)
    • Information Security (1)
    • System Security (4)
  • VMware (4)

Recent Posts

  • Redis 7 Sentinel Infrastructure Installation
  • Oracle Database 19c Multi Data Guard and DML Redirect, Switchover-Failover Operations on Oracle Linux 8
  • Oracle Database 23ai Free Installation Steps on Oracle Linux 9
  • Oracle Database 19c Active Data Guard Installation and DML Redirect, Switchover-Failover Operations on Oracle Linux 8
  • Oracle Database 19c Installation and 19.22 RU Patch Apply on Oracle Linux 8

Resources

  • Oracle
  • PostgreSQL

Blogroll

  • Gökhan Atıl
  • H. Koray Gündüz
  • Hakan Talip Öztürk
  • Zekeriya Beşiroğlu

Web Pages

  • BT Çözümleri

Tag Cloud

Administration Backup and Recovery Cluster Systems Database Administration Database Security Linux Linux Administration MsSQL Server MsSQL Server Error and Solutions MySQL MySQL Administration ORA-00018 ORA-00020 Oracle Oracle 12c Oracle 19c Oracle Administration Oracle Backup and Restore Oracle Data Guard Oracle Data Guard Failover Oracle Data Guard Switchover Oracle Error Solutions Oracle Linux Oracle Rman Backup Oracle Security Oracle SQL Query PostgreSQL PostgreSQL Administration PostgreSQL High Availability PostgreSQL Hot Standby Python SAP Basis Sap Errors and Solutions Sap System Administration SQL SQL Server Administration SQL Server Availability Group Stored Procedure System Administration System Security VMware VMware Administration Windows Windows Batch Script Windows Server

Social

  • View facar1987’s profile on Twitter
  • View facar’s profile on LinkedIn

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 17 other subscribers
©2026 Fatih Acar's blog | Built using WordPress and Responsive Blogily theme by Superb