SqlAlchemy equivalent of pyodbc connect string using FreeTDS

后端 未结 5 1568
借酒劲吻你
借酒劲吻你 2020-12-08 01:37

The following works:

import pyodbc
pyodbc.connect(\'DRIVER={FreeTDS};Server=my.db.server;Database=mydb;UID=myuser;PWD=mypwd;TDS_Version=8.0;Port=1433;\')
         


        
5条回答
  •  臣服心动
    2020-12-08 02:01

    This works:

    import sqlalchemy
    sqlalchemy.create_engine("DRIVER={FreeTDS};Server=my.db.server;Database=mydb;UID=myuser;PWD=mypwd;TDS_Version=8.0;Port=1433;").connect()
    

    In that format, SQLAlchemy just ignores the connection string and passes it straight on to pyodbc.

    Update:

    Sorry, I forgot that the uri has to be url-encoded, therefore, the following works:

    import sqlalchemy
    sqlalchemy.create_engine("DRIVER%3D%7BFreeTDS%7D%3BServer%3Dmy.db.server%3BDatabase%3Dmydb%3BUID%3Dmyuser%3BPWD%3Dmypwd%3BTDS_Version%3D8.0%3BPort%3D1433%3B").connect()
    

提交回复
热议问题