Closed GoogleCodeExporter closed 9 years ago
For anyone else that comes across this, I've come across a good workaround.
pyodbc's create_engine takes a creator argument (see
<http://www.sqlalchemy.org/docs/core/engines.html#custom-dbapi-connect-arguments
>). Define this parameter to be a function which returns a pyodbc connection.
By setting up this connection manually, instead of having SQLAlchemy do it, you
can force
DRIVER={SQL Server Native Client 10.0},
which doesn't trigger the issue.
See
<http://stackoverflow.com/questions/4493614/sqlalchemy-equivalent-of-pyodbc-conn
ect-string-using-freetds/4493770#4493770> for something very similar.
Original comment by iain.ni...@cmascotland.com
on 14 Apr 2011 at 11:36
The last commenter has the best answer. This is something completely out of
the hands of pyodbc - it is simply passing along the arguments and types.
Forcing the use of the latest driver is the best fix.
Original comment by mkleehammer
on 27 Dec 2011 at 1:02
Thanks, iain.ni...@cmascotland.com. The solution you provided works very well.
def connect():
return pyodbc.connect('DRIVER={SQL Server Native Client 10.0};Server=%s;Database=%s;UID=%s;PWD=%s;'%(host, database, username, password))
engine = create_engine('mssql://', creator=connect)
Original comment by zwliu...@gmail.com
on 11 Mar 2012 at 12:55
I'm still having this issue with Python 3 and FreeTDS 0.91, as well as with
Python 2 if unicode strings are passed. Here's me emailing the FreeTDS list in
vain: http://lists.ibiblio.org/pipermail/freetds/2011q3/027336.html
unfortunately "SQL Server Native Client 10.0" is not an option for me here, as
this is freeTDS. Doesn't happen with 0.82.
Original comment by zzz...@gmail.com
on 2 Apr 2013 at 10:38
here's the test script:
import pyodbc
conn = pyodbc.connect(dsn="ms_2005", uid="scott", password="tiger")
cursor = conn.cursor()
# succeeds in py2k, py3k
cursor.execute("""SELECT [COLUMNS_1].[COLUMN_NAME]
FROM [INFORMATION_SCHEMA].[COLUMNS] AS [COLUMNS_1]
WHERE [COLUMNS_1].[TABLE_NAME] = ? AND [COLUMNS_1].[TABLE_SCHEMA] = ?
""", ('short', 'dbo'))
# succeeds in py2k, fails in py3k
cursor.execute("""SELECT [COLUMNS_1].[COLUMN_NAME]
FROM [INFORMATION_SCHEMA].[COLUMNS] AS [COLUMNS_1]
WHERE [COLUMNS_1].[TABLE_NAME] = ? AND [COLUMNS_1].[TABLE_SCHEMA] = ?
""", ('im_a_longer_named_table', 'dbo'))
# fails in both py2k and py3k
cursor.execute("""SELECT [COLUMNS_1].[COLUMN_NAME]
FROM [INFORMATION_SCHEMA].[COLUMNS] AS [COLUMNS_1]
WHERE [COLUMNS_1].[TABLE_NAME] = ? AND [COLUMNS_1].[TABLE_SCHEMA] = ?
""", (u'im_a_longer_named_table', 'dbo'))
Original comment by zzz...@gmail.com
on 2 Apr 2013 at 10:38
anyway, I'll see if I can build into SQLAlchemy this workaround, seems to work
but need to see if it works with 0.82 as well:
cursor.execute("""SELECT [COLUMNS_1].[COLUMN_NAME]
FROM [INFORMATION_SCHEMA].[COLUMNS] AS [COLUMNS_1]
WHERE cast([COLUMNS_1].[TABLE_NAME] as nvarchar(max)) = cast(? as nvarchar(max)) AND [COLUMNS_1].[TABLE_SCHEMA] = ?
""", (u'im_a_longer_named_table', 'dbo'))
Original comment by zzz...@gmail.com
on 2 Apr 2013 at 10:49
Original issue reported on code.google.com by
iain.ni...@cmascotland.com
on 1 Mar 2011 at 3:25Attachments: