Connecting to ms sql db on Windows Server 2008 with pyodbc and python 3.3

1,350 views
Skip to first unread message

Daniel Kraus

unread,
Mar 7, 2013, 1:41:53 PM3/7/13
to sqlal...@googlegroups.com
Hi,

when I try to connect with sqlalchemy and mssql+pyodbc I get this exeption:
"TypeError: The first argument to execute must be a string or unicode query".

It works if I only use pyodbc.

E.g.
>>> conn = pyodbc.connect('DRIVER={SQL Server};Server=127.0.0.1;Database=BOM;UID=guest;PWD=guest')
>>> cursor = conn.cursor()
>>> cursor.execute("select * from Objects")
>>> result = cursor.fetchone()

-> now `result` is a result from the database as it should be.

When I try to connect with sqlalchemy:

>>> engine = sqlalchemy.create_engine('mssql+pyodbc://guest:gu...@127.0.0.1/BOM')
>>> engine.execute("select * from Objects")

-> The above TypeError exception (complete traceback: http://pastebin.com/PHxbynFt )

Not sure if this bug is related: http://www.sqlalchemy.org/trac/ticket/2355

Any ideas what could be wrong and how to fix it?
I would really like to stick with python3 ;)

Thanks,
  Daniel

Michael Bayer

unread,
Mar 7, 2013, 1:58:23 PM3/7/13
to sqlal...@googlegroups.com
its Python 3 related.  that particular ticket refers to how bad of an experience I have when trying to get pyodbc to run well on OSX especially in Python 3.  if things have improved, I can try working on it at least in a Linux VM (I still have low hopes for OSX).


--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+...@googlegroups.com.
To post to this group, send email to sqlal...@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Leonid Ilyevsky

unread,
Jul 9, 2013, 11:18:27 AM7/9/13
to sqlal...@googlegroups.com
I have exact same problem. Any good news on this?
How come it works fine with just pyodbc but not with sqlalchemy? Looks like alchemy does not pass all parameters down properly.


On Thursday, March 7, 2013 1:58:23 PM UTC-5, Michael Bayer wrote:
its Python 3 related.  that particular ticket refers to how bad of an experience I have when trying to get pyodbc to run well on OSX especially in Python 3.  if things have improved, I can try working on it at least in a Linux VM (I still have low hopes for OSX).

On Mar 7, 2013, at 1:41 PM, Daniel Kraus <daniel...@gmail.com> wrote:

Hi,

when I try to connect with sqlalchemy and mssql+pyodbc I get this exeption:
"TypeError: The first argument to execute must be a string or unicode query".

It works if I only use pyodbc.

E.g.
>>> conn = pyodbc.connect('DRIVER={SQL Server};Server=127.0.0.1;Database=BOM;UID=guest;PWD=guest')
>>> cursor = conn.cursor()
>>> cursor.execute("select * from Objects")
>>> result = cursor.fetchone()

-> now `result` is a result from the database as it should be.

When I try to connect with sqlalchemy:

>>> engine = sqlalchemy.create_engine('mssql+pyodbc://guest:guest@127.0.0.1/BOM')

Michael Bayer

unread,
Jul 9, 2013, 11:34:56 AM7/9/13
to sqlal...@googlegroups.com
On Jul 9, 2013, at 11:18 AM, Leonid Ilyevsky <lily...@gmail.com> wrote:

I have exact same problem. Any good news on this?
How come it works fine with just pyodbc but not with sqlalchemy? Looks like alchemy does not pass all parameters down properly.

this issue has been resolved, if you must use Python 3 with pyodbc please use 0.9:  http://www.sqlalchemy.org/download.html#development






Leonid Ilyevsky

unread,
Jul 9, 2013, 1:07:29 PM7/9/13
to sqlal...@googlegroups.com
Thanks Michael, this solved the connection problem.

Could you give me another tip? Now I am trying to get my Table() definition right, so the select statement will be a correct one.
For mssql, it must be something like:

select a, b, c from mydb.dbo.mytable

I just tried to play with it, and I specified table name as the first argument in Table(), and I got:

select "mytable"."a", "mytable"."b", "mytable"."c" from "mytable"

which obviously is not going to work.

Where do I put the database name? The "dbo" schema?

Thanks,

Leonid

Leonid Ilyevsky

unread,
Jul 9, 2013, 1:47:28 PM7/9/13
to sqlal...@googlegroups.com
Never mind, I figured it out.
Reply all
Reply to author
Forward
0 new messages