V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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
XYxe
V2EX  ›  Python

求助, Python 通过 数据库连接池 连接 SQL Server

  •  
  •   XYxe ·
    gao03 · 2016-12-05 10:48:41 +08:00 · 2477 次点击
    这是一个创建于 2705 天前的主题,其中的信息可能已经有所发展或是发生改变。

    想用 python 连接 SQL Server ,还要要用连接池。 直接用 pymssql 是正常的,但是用 DBUtils 和 sqlalchemy 连的时候都提示:

    pymssql.OperationalError) (18456, "用户 'sa' 登录失败。 DB-Lib error message 200 18, severity 14: General SQL Server error: Check messages from the SQL Server DB-Lib error message 20002, severity 9: Adaptive Server connection failed (127.0.0.1:1433) ")

    用的配置都是一样的:

    conn = pymssql.connect(host="127.0.0.1", port=1433, user="sa", password="1234", database="DBtest", charset="utf8")
    engine = create_engine('mssql+pymssql://sa:[email protected]:1433/DBtest/charset="utf8')
    

    查到的一些解决方案都是要设置 TDSVER 环境变量,但是我改了也没有用。 Python2 和 Python3 试了都不可以。

    3 条回复    2016-12-05 21:37:54 +08:00
    Jblue
        1
    Jblue  
       2016-12-05 13:10:47 +08:00   ❤️ 1
    改为 host="127.0.0.1:1433"试试,去掉 port 。
    XYxe
        2
    XYxe  
    OP
       2016-12-05 13:15:00 +08:00
    @Jblue 第一行是 pymssql 的配置,这个是可以用的。
    已经解决了,问题在最后的 charset 写错了,应该是`DBtest?chartset=utf8` 不知道怎么就写成这样了。
    qile1
        3
    qile1  
       2016-12-05 21:37:54 +08:00 via Android
    问下使用 pymssql 如何插入超过 8000 的图像文件。
    有个需求需要数据库直接写入,不能保存路径。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1004 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 23:55 · PVG 07:55 · LAX 16:55 · JFK 19:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.