Issue 109: pyodbc.connect() crashes on Windows 2003 with SQL Server
Status:  Complete
Owner: ----
Closed:  Aug 2010
Reported by decal...@laposte.net, Jul 20, 2010
What steps will reproduce the problem?
1. pyodbc 2.1.7 installed on Python 2.6.5, Windows 2003 SP1, MS SQL Server 2005 Express
2. create an empty database
3. create a system DSN in ODBC data sources for that DB
4. pyodbc.connect(dsn='TEST') crashes the Python interpreter (without exception) from time to time, not always but quite often.
5. same thing with pyodbc.connect('DRIVER={SQL Native Client};SERVER=localhost\\SQLEXPRESS;DATABASE=TEST_DB;Trusted_Connection=yes')
6. The same tests on Vista with SQL Server 2008 Express never crash.

What is the expected output? What do you see instead?
The interpreter should not crash silently. pyodbc should raise an exception if an error occurs.


What version of the product are you using? On what operating system?
pyodbc 2.1.7 installed on Python 2.6.5, Windows 2003 SP1, MS SQL Server 2005 Express

Please provide any additional information below.

The following code can be used to test the issue:

import pyodbc

DSN = 'TEST' # ODBC data source name
DB = 'TEST_DB' # database name
SERVER = 'localhost\\SQLEXPRESS' # server and instance

for i in range(100):
    print 'pyodbc connection', i+1
    # connect via DSN or directly:
    #connection = pyodbc.connect('Trusted_Connection=Yes', dsn=DSN)
    connection = pyodbc.connect('DRIVER={SQL Native Client};SERVER=%s;DATABASE=%s;Trusted_Connection=Yes' % (SERVER, DB))

=> when the issue happens the script stops at 1 without raising any exception, else it should stop at 100.
Jul 20, 2010
#1 decal...@laposte.net
I upgraded the servers to Windows 2003 SP2, and the bug does not seem to happen anymore. So it might be related to ODBC in Windows 2003 SP1 only.
Pyodbc still needs to be fixed to avoid crashing python on legacy servers, unless the bug is in Windows libraries.
Aug 20, 2010
Project Member #2 mkleehammer
If I'm not mistaken, it is actually a race condition in the DCOM libraries.  I worked with Microsoft on this a couple of years ago and got a hotfix which was rolled into SP2.

Status: Done
Nov 21, 2010
Project Member #3 mkleehammer
(No comment was entered for this change.)
Status: Complete