Set connection settings with Pyodbc + UnixODBC + FreeTDS

纵然是瞬间 提交于 2019-12-22 18:23:24

问题


I have a setup using Pyodbc, UnixODBC and FreeTDS, but somewhere in there some options are being set and I don't know where. According to SQL Server Management Studio, my program is sending some settings when it opens the connection:

set quoted_identifier off
set ansi_padding off
set ansi_nulls off
...

But I need a different set of settings:

set quoted_identifier on
set ansi_padding on
set ansi_nulls on
...

Is there any way to change this? If I can't do it with my current setup, are there any other libraries I could use in Python that would let me change it (preferably using the Python Database API)?

Changing settings in the database isn't an option because I have a bunch of other projects that use my current settings.

Solved:

Mark's answer was correct, but I couldn't get it working with FreeTDS/UnixODBC. Adding that info to my odbc.ini file worked perfectly though:

[servername]
... other options ..
AnsiNPW = YES
QuotedID = YES

回答1:


According to MSDN you should be able to set these in the connection string:

cnxn = pyodbc.connect("DSN=someDSN;UID=someUser;PWD=somePass;QuotedID=Yes;AnsiNPW=Yes")


来源:https://stackoverflow.com/questions/3416814/set-connection-settings-with-pyodbc-unixodbc-freetds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!