22

I am trying to run connect to a MSSQL server from an Ubuntu 12.04 webserver with FreeTDS and unixODBC.

Using tsql i can connect to the server with

~$ tsql -S dbs3 -U <username> -P <password>

No problem there.

When I try to connect with isql however, I get the following error message:

~$ isql -v database3 <username> <password>
[S1000][unixODBC][FreeTDS][SQL Server]Unable to connect to data source
[01000][unixODBC][FreeTDS][SQL Server]Unknown host machine name.
[ISQL]ERROR: Could not SQLConnect

My config files are as follows:

odbc.ini

[database3]
Driver=FreeTDS
TDS_Version=8.0
Servername=dbs3
Port=1433
Database=benchmark_res

odbcinst.ini

[FreeTDS]
Description=FreeTDS v0.91
Driver=/usr/local/lib/libtdsodbc.so
Setup=/usr/local/lib/libtdsS.so
Trace=Yes
TraceFile=/tmp/freetds.log
ForceTrave=Yes
UsageCount=1

freetds.conf

# 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 = 4.2

    # 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

[dbs3]
    host = <server-ip>
    port = 1433
    tds version = 8.0

I followed the installation guide 1. here and 2. here

Why isn't isql connecting properly?
My guess is that the mistake is super obvious but I'm just too stupid to see it :D

AndMim
  • 550
  • 1
  • 3
  • 11

3 Answers3

13

The issue was this line in odbc.ini

[database3] must be [dbs3] in your case.

For those that are also having this problem, Check also the

ServerName  = *Points to the name of the server configured in freetds.conf*
Thales Ceolin
  • 2,054
  • 1
  • 18
  • 15
1

If odbc does not find the datasource it means you are providing the wrong one

You are probably trying to connect to dbs3 which will fail if you don't have it in odbc.ini

You should connect to [database3] for ODBC

isql -v database3 <username> <password>
meda
  • 43,711
  • 13
  • 85
  • 120
  • That's what I am doing. I use dbs3 with tsql: tsql -S dbs3 -U -P . Using isql the way you mentiones returns these errors – AndMim Aug 15 '13 at 08:34
  • Ok have you added database3 to your host file – meda Aug 15 '13 at 11:35
  • No, because from my understanding, it should be resolved with the IP I entered in the freetds.conf – AndMim Aug 15 '13 at 13:00
  • both freetds and odbc – meda Aug 16 '13 at 13:20
  • ODBC: `sudo apt-get install unixodbc-dev unixodbc-bin unixodbc` freeTDS: I built that from source. I linked the description I followed in the original question – AndMim Aug 19 '13 at 09:31
1

I had the same problem, I found out that you have to execute the following after each modification of odbc.ini:

odbcinst -i -s -f /etc/odbc.ini

After that, tested this :

isql -v SERVER USER PWD 

and I got this output:

+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
SQL>
deltascience
  • 2,934
  • 5
  • 35
  • 65