No data returned from MSSQL server

Bug #918896 reported by Alan Bell on 2012-01-19
This bug affects 26 people
Affects Status Importance Assigned to Milestone
pymssql (Debian)
Fix Released
pymssql (Ubuntu)

Bug Description


 * 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.

[Test Case]

 * Install python-pymssql to Ubuntu.

 * Inside a 'python' console on the Ubuntu server, use the following python code, replacing values accordingly for your MSSQL servers. The "print" function will return 'None' in the current code base. When fixed, you will get either one value, or a tuple, depending on the results (but you will NOT get 'None'):

import pymssql
dbconn = pymssql.connect(host='FQDN_FOR_DBSERVER', user='DBUSER', password='DBPASSWORD', database='DBNAME')
dbcur = dbconn.cursor()
dbrs = dbcur.fetchone()
print dbrs

[Regression Potential]

 * The patch in the debdiffs is from pymssql upstream. We are on a very old pymssql, but this patch was designed to fix the issue.

[Other Info]

 * Test builds in; these packages in that PPA are used for testing and were used to test the upstream patch.

[Original Description]

this works great in oneiric, but in precise it silently returns empty results from SQL server. The upstream project has relocated and provided a new release, I downloaded and built it and the same code I had started returning results.

ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: python-pymssql 1.0.2+dfsg-1build1
ProcVersionSignature: Ubuntu 3.2.0-9.16-generic 3.2.1
Uname: Linux 3.2.0-9-generic x86_64
ApportVersion: 1.91-0ubuntu1
Architecture: amd64
Date: Thu Jan 19 20:24:31 2012
EcryptfsInUse: Yes
InstallationMedia: Ubuntu 10.10 "Maverick Meerkat" - Release amd64 (20101007)
SourcePackage: pymssql
UpgradeStatus: Upgraded to precise on 2012-01-16 (2 days ago)

Alan Bell (alanbell) wrote :
Alan Bell (alanbell) wrote :

trivial python to show the problem

#!/usr/bin/env python
import _mssql
for row in conn:
    print row

if it is working it should return a bunch of data about columns, in precise it just returns nothing.

Fred (rischfre) wrote :

Have got the same issue, code working properly on 11.04 but no way to get it work on 12.04

#!/usr/bin/env python

import _mssql

conn = _mssql.connect(server='', user='linux', password='linux', database='MYDB')
result = conn.execute_scalar("SELECT MediaLabel FROM T_MediaStatus")
print result


jtscsousa (jtscsousa) wrote :

I had to install python-pymssql_1.9.910-1~oneiric1_amd64.deb from

to solve this problem in 12.04.

torh (tor-h) wrote :

Since this still isn't working. This is also possible to make it work in 12.04:
apt-get uninstall python-pymssql; pip install pymssql

Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in pymssql (Ubuntu):
status: New → Confirmed
Ken Robbins (kenneth-robbins) wrote :

I had this same problem when I upgraded to 12.04. I discovered the problem to be an apparent incompatibility between FreeTDS 0.91 and pymssql 1.0.2. When I downgraded to FreeTDS 0.84RC4 (installed from source), pymssql 1.0.2 works fine. When I upgraded to pymssql 1.9.908 or 2.0.0, pymssql works fine. I decided to downgrade FreeTDS because of this comment:

Ken Robbins (kenneth-robbins) wrote :

Sorry, that should be FreeTDS 0.82RC4.

MrTux (mrtux) wrote :

I had upgrade pymssql to 1.9.912 and using FreeTDS 0.91
pymssql works fine but if I using _mssql it isn't working.

Uninstalling the default package, and installing via pip fixed the problem for me (Ubuntu 12.04-1)

The problem is still the same with Ubuntu 12.10

Neither installing from pip nor from this ppa
can get it to work on quantal.
Did anybody succeed on Ubuntu 12.10?

I confirm what Michael Bewley (michael-bewley) wrote on 2012-10-19. This helped for me:

$ apt-get purge python-pymssql
$ pip install Cython
$ pip install pymssql

Version info:

$ dpkg -l freetds-common
ii freetds-common 0.82-7

Debian 6.0 with.

Andrea Cometa (scigghia) wrote :

I confirm Michael Bewley and Remigijus Jarmalavičius

$ apt-get purge python-pymssql
$ apt-get install freetds-dev
$ pip install Cython
$ pip install pymssql

this solve the problem on Debian Wheezy.

in ubuntu 10.04LTS

>>import pymssql
>>conn=pymssql.connect(host='ip', user='user', password='pass', datababse='database')
>>print row

..........returns no data from SQL server................

apology. is in ubuntu 12.04

Steger Jozsef (steger) wrote :

distribution package python-pymssql 1.0.2+dfsg-1 for amd64 architecture in raring (Ubuntu 13.04) still does the very same.

I have previously compiled the sources downloaded from and set PYTHONPATH environment variable to point also to the folders containing the so binaries. By doing so it works for me.

(I just realized there is a newer tarball same version number, but have not tested that one yet.)

note also another problem with the pymssql shipped with distro, though you get an empty result, the nextresult() method of the cursor will always return True, so you can easily jump in an endless loop


Prepare and execute a database operation (query or command). Parameters may be provided as sequence or mapping and will be bound to variables in the operation. Parameter style for pymssql
 is %-formatting, as in: cur.execute('select * from table where id=%d', id) cur.execute('select * from table where strname=%s', name) Please consult online documentation for more examples and guidelines.


Python 2.7.3 (default, Aug 1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymssql
>>> conn=pymssql.connect(host='IP', user='user', password='pass', database='bd')
>>> cur=conn.cursor()
>>> cur.execute('select * from tbl_tbl where clave=%d',123456)
>>> cur.fetchall()

here show all the results!

SO: Ubuntu 12.04LTS
pymssql: 1.0.2

Thanks Alfonso - you saved me a lot of work.
Pity they couldn't default the last parameter to being '' or None to retain the old behaviour and thus not break existing code.

Anyway I can confirm your results on 12.04 LTS
Here are my precise component versions.

Server: Ubuntu12.04.2 LTS x86_64
python: 2.7.3-0ubuntu2.2
python-pymssql: 1.0.2+dfsg-1build1
freetds-common: 0.91-1

Changed in pymssql (Debian):
status: Unknown → New
Praveen (prajwalpri-shetty) wrote :

I am a beginner to Raspberry Pi wheezy. I want ms sql server connection my application but due to this bug i cant read data from data base any other way to resolve this bug ...(pip command not working )

Thomas Ward (teward) on 2016-06-05
Changed in pymssql (Ubuntu):
importance: Undecided → High
Thomas Ward (teward) wrote :

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.

summary: - returns no data from SQL server
+ No data returned from MSSQL server
Thomas Ward (teward) wrote :

It's very likely every version in Ubuntu is impacted by this.

Thomas Ward (teward) on 2016-06-08
description: updated
tags: added: trusty wily xenial yakkety
Thomas Ward (teward) wrote :

Debdiff uploads to follow after my evening commute home... these address the issue.

Thomas Ward (teward) wrote :

Yakkety DebDiff

Thomas Ward (teward) wrote :

Guess I'll put the other debdiffs here too.

Xenial debdiff.

Thomas Ward (teward) wrote :

Wily debdiff.

Thomas Ward (teward) wrote :

Trusty DebDiff

Thomas Ward (teward) wrote :

Precise Debdiff

Changed in pymssql (Ubuntu Precise):
importance: Undecided → High
Changed in pymssql (Ubuntu Trusty):
importance: Undecided → High
Changed in pymssql (Ubuntu Wily):
importance: Undecided → High
Changed in pymssql (Ubuntu Xenial):
importance: Undecided → High
Changed in pymssql (Ubuntu Trusty):
status: New → Confirmed
Changed in pymssql (Ubuntu Xenial):
status: New → Confirmed
Changed in pymssql (Ubuntu Precise):
status: New → Confirmed
Changed in pymssql (Ubuntu Wily):
status: New → Confirmed
Thomas Ward (teward) wrote :

Sponsors Team: First, check/sponsor Yakkety. Once that's been verified and such, we can continue on to the other releases.

Changed in pymssql (Debian):
status: New → Confirmed
Robie Basak (racb) wrote :


Thank you for the debdiffs! Unfortunately pymssql is a version 1.0 source package, so I'm not sure quilt makes sense. I suppose it will work as you have supplied it, since your debdiffs would cause the package to ship with quilt applied. I've not seen it done this way before though, so I'm not comfortable sponsoring it without someone senior telling me it's OK. I would have expected the patch to just be applied without quilt (perhaps with more information in debian/changelog as dep3 wouldn't be available).

Thomas Ward (teward) wrote :

I've removed the sponsors team for now until I can redo the debdiffs.

Geoffrey Thomas (geofft) wrote :

Hi Thomas,

A few months ago I pushed a branch updating the python-pymssql packaging to Debian's git repository, but I'm still waiting to hear back from the maintainer. I'll attempt to get sponsorship for a team upload to Debian soon - if so, it's possibly better to just sync the package from Debian.

See and . I can update this to 2.2.0. I think your debdiffs were removed from the bug - please do check my work and see if I got all the changes you were going to make.

Among other things I updated the source format to 3.0 (quilt).

Thomas Ward (teward) wrote :


That sounds great for updating the development release, but a straight sync may not work for the stable release update to the rest of the world.

The debdiffs I had done were to 'nitpick' the upstream fixes and apply them to the older package versions, not to redo the packaging. Those nitpicks were rejected by Sponsors, so I never got to redo them.

We need compatible debdiffs for the older releases, using the upstream changes to fix only that issue, unless a version bump is determined to be preferable.

Changed in pymssql (Debian):
status: Confirmed → Fix Released
Thomas Ward (teward) wrote :

Setting Zesty to Confirmed/High, because I did some testing here on a Zesty container with the MSSQL instance I have here and the same "No data returned" issue cropped up.

There is an updated version in Artful's Proposed repository that might fix this for Artful, though, since it's updated to a release that will resolve most of the issues observed thus far.

Changed in pymssql (Ubuntu Zesty):
status: New → Confirmed
importance: Undecided → High
Peter Schwenke (bluetoad) wrote :

I can't believe this is still going on. I no longer work in software and have no use for this but as pointed out on other related pymssql bugs I had this working many years ago and had a working version in my bluetoad PPA. I'll just shake my head and unsubscribe from this!

Changed in pymssql (Ubuntu Artful):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.