推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
zrp1994
V2EX  ›  Python

求教,多进程下使用 PyODBC 连接 SQL Server 读取数据,一段时间后报出“通讯链接失败”错误……

  •  
  •   zrp1994 · Mar 8, 2016 · 3460 views
    This topic created in 3862 days ago, the information mentioned may be changed or developed.

    Python 是在本地机上运行的, SQL Server 在服务器上。每个进程每次大概读取几千条数据,计算完成后再读下面几千条。刚开始连接的一段时间内都可以正常的接受数据并计算,然而一段时间后所有进程都会报出:

    '08S01', '[08S01] [Microsoft][ODBC SQL Server Driver]通讯链接失败 (0) (SQLExecDirectW)'
    

    可以确认的是这个时候的网络并没有中断,并且重启程序后恢复正常,直到一段时间后再次出错。我怀疑是 SQL Server 的连接数过多导致错误,但是程序的进程数是固定的,而且每次读取数据并不建立新的 Cursor 。

    # 这个调用了一次
    def connect():
        cursor = None
        try:
            mssql_connection = pyodbc.connect('DRIVER={{SQL Server}};SERVER={};DATABASE={};UID={};PWD={}'.format(SERVER_NAME, DB_NAME, DB_USER_NAME, DB_USER_PWD), unicode_results=True)
            cursor = mssql_connection.cursor()
        except:
            traceback.print_exc()
        return cursor
    

    现在没头绪了……希望有过来人提供下思路,求轻喷

    2 replies  •  2016-04-28 09:52:27 +08:00
    zrp1994
        1
    zrp1994  
    OP
       Mar 9, 2016
    沉的好快呀,我顶一下吧
    zrp1994
        2
    zrp1994  
    OP
       Apr 28, 2016
    最终发现问题是实验室网络不稳定造成的……结贴。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1890 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 00:02 · PVG 08:02 · LAX 17:02 · JFK 20:02
    ♥ Do have faith in what you're doing.