We are having an error when launching the tsql/isql in my python script. And I follow the solutions from the other answers but I couldn't debug it.
Here's the error:
Traceback (most recent call last):
File "test.py", line 10, in <module>
cnxn = pyodbc.connect('DRIVER=FreeTDS;SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password+';TDS_Version=4.2;')
pyodbc.OperationalError: ('08001', u'[08001] [FreeTDS][SQL Server]Unable to connect to data source (0) (SQLDriverConnect)')
Here's the script:
import pyodbc
server = 'shared-sql-ubu.xxx.com'
database = 'db'
username = 'root'
password = 'root'
print('DRIVER=FreeTDS;SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password+';TDS_Version=4.2;')
cnxn = pyodbc.connect('DRIVER=FreeTDS;SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password+';TDS_Version=4.2;')
cursor = cnxn.cursor()
With this command:
$ tsql -C v
In terminal prints:
Compile-time settings (established with the "configure" script)
Version: freetds v1.00.82
freetds.conf directory: /etc/freetds
MS db-lib source compatibility: no
Sybase binary compatibility: yes
Thread safety: yes
iconv library: yes
TDS version: 4.2
iODBC: no
unixodbc: yes
SSPI "trusted" logins: no
Kerberos: yes
OpenSSL: no
GnuTLS: yes
MARS: no
In /etc/odbc.ini
[sqlserver]
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Description = ODBC to SQLserver via FreeTDS
Trace = No
Servername = sqlserver
Database = db
TDS_Version = 4.2
In /etc/odbcinst.ini
[FreeTDS]
Description = FreeTDS Driver
Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
client charset = utf-8
In /etc/freetds/freetds.conf
[Global]
TDS_Version = 4.2
client charset = UTF-8
[sqlserver]
host=shared-sql-ubu
port=1433
tds version = 4.2
Any help will be appreciated, Thanks!
=======================================
Problem solved:
New version of /etc/odbc.ini
[sqlserver]
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
Description=ODBC to SQLserver via FreeTDS
Trace=No
Server=tcp:172.0.0.0 # the id of your sqlserver
#Database=master
#TDS_Version=4.2
New version of /etc/odbcinst.ini
[FreeTDS]
Description=FreeTDS Driver
Driver=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
#Setup=/usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so
#client charset=utf-8
UsageCount=1
Note that some lines are commented because they are not really doing anything!