使用Pyodbc + UnixODBC + FreeTDS设置连接设置

问题描述:

我有一个使用Pyodbc,UnixODBC和FreeTDS的安装程序,但是其中某些位置正在设置一些选项,我不知道在哪里.根据SQL Server Management Studio,我的程序在打开连接时正在发送一些设置:

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
...

有什么办法可以改变这个?如果我无法使用当前的设置进行操作,是否可以在Python中使用其他库来更改它(最好使用Python数据库API)?

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.

Mark的答案是正确的,但是我无法将其与FreeTDS/UnixODBC一起使用.不过,将该信息添加到我的odbc.ini文件中的工作仍然很完美:

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

根据 MSDN ,您应该可以在连接字符串中进行设置:

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")