Connect to MS SQL database using freetds, unixodbc and python
Asked Answered
M

0

6

I'm running Ubuntu 12.04 on a 32-bit computer, and I want to connect to my MS SQL database using freetds, unixodbc and python, but I'm getting an error:

>>> import pyodbc
>>> conn = pyodbc.connect('DSN=TS;UID=myusername;PWD=mypassword')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pyodbc.Error: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')

This is my /etc/freetds.conf file:

[TS]
host = 192.168.254.50
port = 1433
tds version = 7.0
client charset = UTF-8

This is my /etc/odbc.ini file:

--- /etc/odbc.ini ---
[TS]
Description = "test"
Driver = FreeTDS
Server = 192.168.254.50
Port = 1433
Database = db_name

This is my /etc/odbcinst.ini file:

--- /etc/odbcinst.ini ---
[FreeTDS]
Description = FreeTDS
Driver = /usr/lib/i386-linux-gnu/odbc/libtdsodbc.so

When I try to test this out on bash using tsql, it works:

$ tsql -S TS -U myusername -P mypassword
locale is "en_SG.UTF-8"
locale charset is "UTF-8"
using default charset "UTF-8"
1> use db_name
2> go
1> select top 10 label from db_name.tablename
2> go
[... data here ...]
(10 rows affected)
1> 

However, testing it using isql doesn't, and gives a very similar error as in the python prompt:

$ isql -v TS myusernam mypassword
[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified
[ISQL]ERROR: Could not SQLConnect

Can anyone help me out please?

Malo answered 23/6, 2014 at 8:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.