python - Error connecting to SQL Server from Ubuntu+PYODBC -


i found many similar question none of solutions worked me. seems pretty simple matter still can't find solution.

i'm using headless ubuntu server connect sql server on windows server 2008 using python script using pyodbc. script runs on local windows machines, when try on ubuntu server error:

error: ('im002', '[im002] [unixodbc][driver manager]data source name not found, , no default driver specified (0) (sqldriverconnect)') 

the connection string i'm using is:

connectionstring='driver={dbserverdsn};server=10.23.11.10;database=market;uid=usr;pwd=pwd;tds_version=7.2;port=1433' 

any thoughts ? in advance

edit : adding main files

odbc.ini

[dbserverdsn]     driver = freetds     server = 10.23.11.10     port = 1433     database=markets     tds_version = 7.2 

odbcinst.ini

[freetds]     description = v0.91 protocol v7.2     driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so 

freetds.conf

[global]     # tds protocol version, use:     # 7.3 sql server 2008 or greater (tested through 2014)     # 7.2 sql server 2005     # 7.1 sql server 2000     # 7.0 sql server 7     tds version = 7.2     port = 1433     text size = 64512  # typical microsoft server [dbserverdsn]     host = 10.23.11.10     port = 1433     tds version = 7.2 

microsoft comes pre-installed driver speak sql server, ubuntu not. freetds provides best driver i've used (the 1 provided ms has given me problems). here's how... on ubuntu, install pre-requisites:

# install pre-requesite packages sudo apt-get install unixodbc unixodbc-dev freetds-dev freetds-bin tdsodbc 

you need configure /etc/freetds/freetds.conf bridge unixodbc sql server next:

[global]     # tds protocol version, use:     # 7.3 sql server 2008 or greater (tested through 2014)     # 7.2 sql server 2005     # 7.1 sql server 2000     # 7.0 sql server 7     tds version = 7.2     port = 1433     text size = 64512  # typical microsoft server [dbserverdsn]     host = dbserver.domain.com     port = 1433     tds version = 7.2 

here's plug unixodbc freetds in /etc/odbcinst.ini , give path freetds driver:

[freetds] description = v0.91 protocol v7.2 driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so 

last not least, edit /etc/odbc.ini python / unixodbc can see entire stack , freetds data source:

[dbserverdsn] driver = freetds server = dbserver.domain.com port = 1433 tds_version = 7.2 

you can test problems on ubuntu's command line 'tsql' , 'isql' command line utilities , post errors receive.

then, connection string:

connectionstring='driver={freetds};server=10.23.11.10;port=1433;database=market;uid=*;pwd=*;tds_version=7.2' 

good luck!


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -