问题
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