2

I am trying to run connect to a MSSQL server from a RHEL 5.5 server with FreeTDS and unixODBC.

Using tsql i can connect to the server with

tsql -S mssqltest -U <username> -P <password>

It's getting connected successfully

isql -v mssqltest 'username' 'password' -b -q

Also connects without any problem

But in perl I get a error message as follows

DBI connect('mssqltest',<username>,...) failed: [unixODBC][Driver Manager]Can't open lib '/usr/local/lib/libtdsodbc.so' : file not found (SQL-01000) at test.pl line 14
Can't connect to DBI:ODBC:mssqltest: [unixODBC][Driver Manager]Can't open lib '/usr/local/lib/libtdsodbc.so' : file not found (SQL-01000) at test.pl line 14.

I tried using FreeTDS as ODBC Driver that also gives similar error also I tried using servername instead of server_ip, but the error continues

DBI connect('Driver=FreeTDS;Server=<server_ip>',<username>,...) failed: [unixODBC][Driver Manager]Can't open lib '/usr/local/lib/libtdsodbc.so' : file not found (SQL-01000) at test.pl line 14
Can't connect to DBI:ODBC:Driver=FreeTDS;Server=<server_ip>: [unixODBC][Driver Manager]Can't open lib '/usr/local/lib/libtdsodbc.so' : file not found (SQL-01000) at test.pl line 14.

my perl code

#!/usr/bin/perl -w
use strict;

use DBI;

# Replace datasource_name with the name of your data source.
# Replace database_username and database_password
# with the SQL Server database username and password.
my $data_source = q/DBI:ODBC:mssqltest/;
my $user = q/<username>/;
my $password = q/<password>/;

# Connect to the data source and get a handle for that connection.
my $dbh = DBI->connect($data_source, $user, $password)
    or die "Can't connect to $data_source: $DBI::errstr";

# This query generates a result set with one record in it.
my $sql = "SELECT TOP 3 * FROM tablename";

# Prepare the statement.
my $sth = $dbh->prepare($sql)
    or die "Can't prepare statement: $DBI::errstr";

# Execute the statement.
$sth->execute();

# Print the column name.
print "$sth->{NAME}->[0]\n";

# Fetch and display the result set value.
while ( my @row = $sth->fetchrow_array ) {
   print "@row\n";
}

# Disconnect the database from the database handle.
$dbh->disconnect;

My config files are:

FreTDS/odbc.ini

;
;  odbc.ini
;
[ODBC Data Sources]
JDBC = Sybase JDBC Server

[JDBC]
Driver          = /usr/local/lib/libtdsodbc.so
Description     = Sybase JDBC Server
Trace           = No
Servername      = JDBC
Database        = pubs2
UID             = guest

[Default]
Driver          = /usr/local/lib/libtdsodbc.so

odbc.ini

[ODBC Data Sources]
TS = FreeTDS

[TS]
Driver = FreeTDS
Description = ODBC to SQLServer via FreeTDS
Trace = No
Servername = sql-server
Database = RKDB

[mssqltest]
Description     = MS SQL connection to mssqltest database
Driver          = FreeTDS
Database        = RKDB
Server          = <server_ip>
UserName        = <username>
Password        = <password>
Trace           = Yes
Port            = 1754

obcinst.ini

[FreeTDS]
Description=TDS driver (Sybase/MS SQL)
Driver=/usr/local/lib/libtdsodbc.so
UsageCount=2

freetds-dev.0.99.761/freetds.conf

#   $Id: freetds.conf,v 1.12 2007-12-25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".

# Global settings are overridden by those in a database
# server specific section
[global]
        # TDS protocol version
        tds version = auto

        # Whether to write a TDSDUMP file for diagnostic purposes
        # (setting this to /tmp is insecure on a multi-user system)
;       dump file = /tmp/freetds.log
;       debug flags = 0xffff

        # Command and connection timeouts
;       timeout = 10
;       connect timeout = 10

        # If you get out-of-memory errors, it may mean that your client
        # is trying to allocate a huge buffer for a TEXT field.
        # Try setting 'text size' to a more reasonable limit
        text size = 64512

# A typical Sybase server
[egServer50]
        host = symachine.domain.com
        port = 5000
        tds version = 5.0

# A typical Microsoft server
[egServer70]
        host = ntmachine.domain.com
        port = 1433
        tds version = 7.0

[mssqltest]
        host = <server_ip>
        port = 1754
        tds version = 8.0

/usr/local/etc/freetds.conf

#   $Id: freetds.conf,v 1.12 2007-12-25 06:02:36 jklowden Exp $
#
# This file is installed by FreeTDS if no file by the same
# name is found in the installation directory.
#
# For information about the layout of this file and its settings,
# see the freetds.conf manpage "man freetds.conf".

# Global settings are overridden by those in a database
# server specific section
[global]
        # TDS protocol version
        tds version = auto

        # Whether to write a TDSDUMP file for diagnostic purposes
        # (setting this to /tmp is insecure on a multi-user system)
;       dump file = /tmp/freetds.log
;       debug flags = 0xffff

        # Command and connection timeouts
;       timeout = 10
;       connect timeout = 10

        # If you get out-of-memory errors, it may mean that your client
        # is trying to allocate a huge buffer for a TEXT field.
        # Try setting 'text size' to a more reasonable limit
        text size = 64512

# A typical Sybase server
[egServer50]
        host = symachine.domain.com
        port = 5000
        tds version = 5.0

# A typical Microsoft server
[sql-server]
        host = TH-SSRS-DB
   InstanceName = RKSSRSDB
        #port = 1754
        tds version = 8.0

client charset = UTF-8

[mssqltest]
        host = <server_ip>
        port = 1754
        tds version = 8.0

Please help.

  • The `Driver` entry in your config files is `/usr/local/lib/libtdsodbc.so`, but `DBI` is saying that it can't find it. Are you certain the file is there? Does your perl process have sufficient privileges to open it? `.so` files have traditionally had privileges of 0755, but 0644 should be adequate. – Borodin Feb 17 '18 at 12:08
  • Yes it has a 755 permission set – Binayak Chatterjee Feb 17 '18 at 14:18
  • https://stackoverflow.com/questions/12031897/missing-libtdsodbc-so-in-freetds-dev-mssql-on-ubuntu – xxfelixxx Feb 18 '18 at 02:44

0 Answers0