简体   繁体   English

与pyodbc到镜像MS SQL Server的第二次连接上的Segfault

[英]Segfault on 2nd connection with pyodbc to mirrored MS SQL Server

I'm facing an issue with a Python script that connects to a mirrored MS SQL server DB. 我遇到了与镜像MS SQL Server DB连接的Python脚本问题。 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. 应用服务器和数据库实例均在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. 第一个连接(c1)成功,但是第二个连接(c2)立即因段错误而失败。 "mydb" is mirrored to a second server (sql-server-02). “ mydb”镜像到第二台服务器(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: 版本:

  • Microsoft SQL Server: 12.00.2000 (latest) Microsoft SQL Server:12.00.2000(最新)
  • Python: 2.7.6 的Python:2.7.6
  • pyodbc: 3.0.10 (latest) pyodbc:3.0.10(最新)
  • unixODBC: 2.2.14p2-5ubuntu5, 2.3.0, 2.3.4 (latest) unixODBC:2.2.14p2-5ubuntu5、2.3.0、2.3.4(最新)
  • MS ODBC driver for RedHat: 11.0.1790.0, 11.0.2270.0 (latest) 用于RedHat的MS ODBC驱动程序:11.0.1790.0,11.0.2270.0(最新)

To add here, Java code performing the same steps works fine. 要在此处添加,执行相同步骤的Java代码可以正常工作。

Any ideas? 有任何想法吗?

The MSODBC driver has a lot of known issues, especially with multithreading. MSODBC驱动程序有很多已知问题,尤其是在多线程方面。 It sounds like you're running into this. 听起来您好像遇到了这种情况。 I ran into it with Django's runserver; 我在Django的runserver中遇到了这个问题; it would only work (and still with bugs in SQLRowCount) with the --nothreading option for Django's runserver. 只有使用Django的runserver的--nothreading选项,它才能正常工作(并且仍然存在SQLRowCount中的错误)。

Fortunately, Microsoft is now assembling a team to make a better performing, reliable driver (thank you, MS!). 幸运的是,Microsoft现在正在组建一个团队,以提供性能更好,更可靠的驱动程序(谢谢您,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. 同时,我使用的是FreeTDS 0.95(它支持TDS 7.3版,即SQL Server 2008),这对我来说非常好。 Give that a try? 试试看吗? Good luck. 祝好运。

It is a known issue in certain versions of MS ODBC + unixODBC. 在某些版本的MS ODBC + unixODBC中,这是一个已知问题。 By upgrading to unixODBC-2.3.2 and the latest MS ODBC driver, solves the issue on some distributions of linux, eg ubuntu and debian. 通过升级到unixODBC-2.3.2和最新的MS ODBC驱动程序,解决了某些Linux发行版上的问题,例如ubuntu和debian。 You can follow the steps for upgrade here: https://blog.afoolishmanifesto.com/posts/install-and-configure-the-ms-odbc-driver-on-debian/ it solved the double connection issue - can open multiple connections without segfaulting. 您可以在此处按照升级步骤进行操作: https : //blog.afool​​ishmanifesto.com/posts/install-and-configure-the-ms-odbc-driver-on-debian/它解决了双重连接问题-可以打开多个连接没有segfaulting。

The same upgrade / steps did not work for me on RedHat 7.1 though - you still get a segfault on opening a connection twice in same session. 尽管在RedHat 7.1上,相同的升级步骤对我不起作用-在同一会话中两次打开连接仍会遇到段错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 pyodbc 连接到在 docker 容器上运行的 MS SQL Server - pyodbc connection to MS SQL Server running on a docker container SQLAlchemy PyODBC MS SQL Server少DSN连接 - SQLAlchemy PyODBC MS SQL Server DSN-less connection PYODBC + MS SQL SERVER 连接与 Encrypt=yes 未连接 - PYODBC + MS SQL SERVER connection with Encrypt=yes not connecting 远程连接到 MS SQL - 使用 pyodbc 时出错与使用 SQL Server Management Studio 成功 - Remote connection to MS SQL - Error using pyodbc vs success using SQL Server Management Studio 使用pyodbc将Python连接到MS SQL Server - Connect Python to MS SQL Server using pyodbc 编码从pyodbc到MS SQL Server的调用 - Encoding calling from pyodbc to a MS SQL Server 我可以在与pyodbc和MS SQL Server的一个连接上使用多个游标吗? - Can I use multiple cursors on one connection with pyodbc and MS SQL Server? 如何为 SQL Server/Linux 堆栈的 python/pyodbc/unixODBC/MS ODBC Driver 11 设置数据库连接超时? - How to set a DB connection timeout for a python/pyodbc/unixODBC/MS ODBC Driver 11 for SQL Server/Linux stack? SQL Server 2017 中的 pyodbc 连接 - pyodbc connection within SQL Server 2017 如何使用 sqlalchemy+pyodbc 和 MS SQL Server 中的多个数据库为 pandas read_sql 创建 sql alchemy 连接? - How to create sql alchemy connection for pandas read_sql with sqlalchemy+pyodbc and multiple databases in MS SQL Server?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM