2

I just spent hours trying to acomplish a simple task. I had python code that I used to run in windows, and it access a MS SQL db on a windows server 2008. I set up a ubuntu server and want to run this script in this server. after having installed pyodbc, freetds and a bunch of other packages I still can't connect to the DB. The windows connection string I was using was:

connectionString='DRIVER={SQL Server};SERVER=IP;DATABASE=Market;UID=usr;PWD=psw

after researching a lot I ended up with three connection files odbc.ini odbcinst.ini and freetds.conf and they look, respectively like this:

odbc.ini:

[sqlserverdatasource] Driver = FreeTDS Description = ODBC connection via FreeTDS Trace = No Servername = sqlserver Database = Market;

odbcinst.ini

[FreeTDS] Description = TDS driver (Sybase/MS SQL) Driver = /usr/lib/x86_64-linux-gnu/odbc/libtdsodbc.so Setup = /usr/lib/x86_64-linux-gnu/odbc/libtdsS.so CPTimeout = CPReuse = FileUsage = 1

freetds.conf

[sqlserver] host = 10.23.11.10; port = 1433; tds version = 5.0

Now i've been trying to test the connection with the following

tsql -S sqlserver

but i get the following error

Error 20017 (severity 9): Unexpected EOF from the server OS error 115, "Operation now in progress" Error 20002 (severity 9): Adaptive Server connection failed

I thought it would take a couple of minutes to make it work but I've wasted many hours. any help is deeply appreciated. thank you.

  • I had to specify the PORT=1433 and TDS_Version=7.2 – tolos Jan 28 '16 at 4:36
1

If you are trying to connect to SQL Server from your linux machine I highly recommend you follow this link https://azure.microsoft.com/en-us/documentation/articles/sql-database-develop-python-simple-ubuntu-linux/

This uses another python driver pymssql which uses FreeTDS to connect to SQL Server. Let me know if this helps.

Best,
Meet

  • Hey, Meet. You may want to update the Ubuntu instructions on this page since they no longer seem to work for SSL connections with Ubuntu 16.04 and the current version of pymssql. If you're interested, I have posted my own recipe for Ubuntu 16.04 and pymssql 2.1.3 here. – Gord Thompson Sep 12 '16 at 0:16
  • True. I will do that. – meet-bhagdev Sep 12 '16 at 21:01
1

Recently we developed and tested our SQL Server ODBC drivers with pyODBC 3.0.7 on Python 3.3 and connection was successful. All worked fine.

Try to download latest pyODBC driver https://github.com/mkleehammer/pyodbc and this SQL Server ODBC driver
There is a connection strings example in documentation. You may use it.

0

I regularly connect to DBs using python. My connection string is as follows:

ConnectionString='DSN=MyDSN'

DSN stands for Data source Name and its details are are stored in the odbc.ini file in the form you use:

[MyDSN]

Driver = FreeTDS

Description = ODBC connection via FreeTDS

Trace = No

Servername = sqlserver

Database = Market

USER = DBuser

Password = yourpwd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.