2

I'm trying to fetch the data from server so I tried as follow

#!/usr/bin/python
import pymssql
conn = pymssql.connect(host='xxxx', user='xxx', password='xxx', database='xxx')


cursor = conn.cursor()
x2 = 'select * from result where url like\'%get content%\''
cursor.execute(x2)
data = cursor.fetchall()
field_names = [i[0] for i in cursor.description]
print field_names
print data

When I run this program it only give the column name, data variable is empty. I don't know what is the reason. How can I fix it?

I'm running the same script in windows there is no problem. But when I execute the script in Ubuntu 14.04 the data variable is empty.

9
  • Can you check cursor.rowcount after or before fetchall() command. Commented Jan 10, 2017 at 12:45
  • Is it giving -1 in both cases (before & after fetchall)? If yes, then there is problem query or connection.. Commented Jan 10, 2017 at 12:49
  • @HarshaBiyani Yes both cases it's result -1. If query or connection is problem mean how the column gets print? Commented Jan 10, 2017 at 12:52
  • ohh correct.. Have you tried with simple query? like - select * from result? Commented Jan 10, 2017 at 12:56
  • @HarshaBiyani Yep. I tried. But rows are not fetching. :( Commented Jan 10, 2017 at 13:06

2 Answers 2

4
+50

This is a known bug of PyMSSQL 1.0.x on Ubuntu. See No data returned from MSSQL server. Solution is to upgrade it to version >= 2.0.1.

Due to an issue with PyMSSQL 1.0.x and the version of FreeTDX in the repositories, PyMSSQL no longer returns any information from MSSQL database queries. This means you cannot use fetchone() or fetchall() or similar methods to get data back from a database query.


Thomas Ward (teward) wrote on 2016-06-05:

This is due to an incompatibility between freetdx and PyMSSQL 1.0.x.

Workaround is to remove the python-pymssql package, and run pip install pymssql or easy_install --upgrade pymssql or similar, to get the most up to date pymssql version, greater than or equal to 2.0.1.

ALso confirmed this issue on Xenial and Yakkety, as well as Trusty.

Sign up to request clarification or add additional context in comments.

Comments

-1

You can try pyodbc on ubuntu 14.04

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.