PyOdbc fails to connect to a sql server instance

前端 未结 2 771
Happy的楠姐
Happy的楠姐 2021-01-19 20:37

I am trying to connect to a sql server instance using pyodbc version 3.0.6., SQLAlchemy 1.0.4 on Windows 7 using a Python 2.7 (32 bit). I am using a connection string as fol

相关标签:
2条回答
  • 2021-01-19 21:36

    OK, this seems to have resolved the issue

    import urllib    
    connection_string = "DRIVER={SQL Server};Database=people;SERVER=gagan;UID=sa;PWD=admin1"
    connection_string = urllib.quote_plus(connection_string) 
    connection_string = "mssql+pyodbc:///?odbc_connect=%s" % connection_string
    
    0 讨论(0)
  • 2021-01-19 21:38

    There are other drivers available in Windows ecosystem, you can try the other 2 as well :)

    There are actually two or three SQL Server drivers written and distrubuted by Microsoft: one referred to as "SQL Server" and the other as "SQL Native Client" and "SQL Server Native Client 10.0}".

    DRIVER={SQL Server};SERVER=cloak;DATABASE=test;UID=user;PWD=password

    DRIVER={SQL Native Client};SERVER=dagger;DATABASE=test;UID=user;PWD=password

    DRIVER={SQL Server Native Client 10.0};SERVER=dagger;DATABASE=test;UID=user;PWD=password

    Reference: https://code.google.com/p/pyodbc/wiki/ConnectionStrings

    EDIT: 1

    Since SQLSoup which is written on top of SQLAlchemy you will have to use the following connection string:

    "mssql+pyodbc://sa:admin1@mymachinename/mydb"
    

    Reference: http://docs.sqlalchemy.org/en/rel_0_8/dialects/mssql.html#module-sqlalchemy.dialects.mssql.pyodbc

    0 讨论(0)
提交回复
热议问题