Segfault for 2nd connection with pyodbc for mirrored MS SQL Server

I ran into a problem with a Python script that connects to a MS SQL mirror database. It throws a segmentation error when I try to connect to the database a second time. Both application servers and DB instances run on the Google Compute Engine.

Here is some code that replicates the problem:

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) completed successfully, but the second connection (c2) does not work immediately with segfault. "mydb" is mirrored on the second server (sql-server-02). Using a non-mirrored database or disabling mirroring for this database forces it to leave.

We tried to update several libraries, and this did not help to solve the problem. Versions:

  • Microsoft SQL Server: 12.00.2000 (latest version)
  • Python: 2.7.6
  • pyodbc: 3.0.10 (last)
  • unixODBC: 2.2.14p2-5ubuntu5, 2.3.0, 2.3.4 (last)
  • MS ODBC driver for RedHat: 11.0.1790.0, 11.0.2270.0 (last)

To add here, Java code doing the exact same thing works fine.

Any ideas?

+6
source share
2 answers

The MSODBC driver has many known issues, especially with multithreading. It looks like you are handling this. I came across it with a Django server; it will work (and still with errors in SQLRowCount) with the --nothreading to start the Django server.

Fortunately, Microsoft is now putting together a team to make a more efficient and reliable driver (thanks, MS!). In the meantime, I am using FreeTDS 0.95 (which supports prior to TDS version 7.3, a SQL Server 2008), which treated me very well. Try to try? Good luck.

+3
source

This is a known issue in some versions of MS ODBC + unixODBC. Upgrading to unixODBC-2.3.2 and the latest MS ODBC driver, this problem is solved in some Linux distributions, for example. ubuntu and debian. You can follow these steps to upgrade: https://blog.afoolishmanifesto.com/posts/install-and-configure-the-ms-odbc-driver-on-debian/ he solved the dual connection problem - he can open multiple connections without segfault .

The same updates / steps didn’t work for me on RedHat 7.1, but you still get segfault when you open the connection twice in the same session.

-1
source

All Articles