On Mar 22, 2011, at 10:12 PM, Thang Nguyen wrote:

> Hi,
> 
> I tried to use sqlalchemy (linux) to connect to MS SQL server
> (Windows) via ODBC (pyodbc).  I got the errors below, just wonder if
> something was not done correctly.  Please shed a light, and thanks in
> advance.
> 
> TPN
> 
> 
> import pyodbc
> import sqlalchemy
> from sqlalchemy import *
> pycon = 
> pyodbc.connect("DRIVER={FreeTDS};SERVER=testserver;DATABASE=TEST_UDC;PORT=1435;UID=Test_Foo;PWD=Test_Foo1")
> cursor = pycon.cursor()
> cursor.execute("select * from test_product")
> rows = cursor.fetchall()
> for row in rows:
>    print row
> 
> # up to this point, it works nicely, each row is printed correctly.
> 
> engine = create_engine('mssql://', creator=pycon)
> metadata = MetaData(bind=engine)
> result = engine.execute("select * from test_product")
> # it fails here

creator needs to be a function:

def pycon():
    return pyodbc.connect(...)

create_engine(...., creator=pycon)


> 
> --- Here is the error message --
> ....
> ....
> 
>  return _ConnectionRecord(self)
>  File "/xyz/sqlalchemy/pool.py", line 198, in __init__
>    self.connection = self.__connect()
>  File "/xyz/sqlalchemy/pool.py", line 261, in __connect
>    connection = self.__pool._creator()
> TypeError: 'pyodbc.Connection' object is not callable
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "sqlalchemy" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> For more options, visit this group at 
> http://groups.google.com/group/sqlalchemy?hl=en.
> 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to