I'm facing an issue with a Python script that connects to a mirrored MS SQL server DB. It's throwing a segmentation fault when I try connecting to the DB for the second time. Both the app server and the DB instances are running on Google Compute Engine.
Here's some code replicating the issue:
import pyodbc
params = {
'autocommit': True,
'uid': 'myuser',
'tds_version': '8.0',
'DRIVER': '{mssql}',
'pwd': 'mypassword',
'server': 'sql-server-01',
'database': 'mydb',
'port': 1433,
}
c1 = pyodbc.connect(**params)
c2 = pyodbc.connect(**params)
The first connection (c1) succeeds, but the second connection (c2) fails immediately with segfault. "mydb" is mirrored to a second server (sql-server-02). Using a non-mirrored DB, or disabling mirroring for this DB, makes it go away.
We have tried upgrading several libs, and that didn't fix the issue. Versions:
To add here, Java code performing the same steps works fine.
Any ideas?
The MSODBC driver has a lot of known issues, especially with multithreading. It sounds like you're running into this. I ran into it with Django's runserver; it would only work (and still with bugs in SQLRowCount) with the --nothreading
option for Django's runserver.
Fortunately, Microsoft is now assembling a team to make a better performing, reliable driver (thank you, MS!). In the meantime, I use FreeTDS 0.95 (which supports up to TDS version 7.3, a la SQL Server 2008), which has treated me very well. Give that a try? Good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With