Hello.
The task is to execute stored procedure which writes data to database
in SQL Server 2008 using SQLAlchemy 0.7.1 in Python 2.7.2. SQLAlchemy
uses pyodbc 2.1.8. When trying to use SQLAlchemy, data is not written
to database:
from sqlalchemy.engine import create_engine
from sqlalchemy.orm import create_session
e = create_engine('mssql+pyodbc://user:password@localhost/db')
s = create_session(bind=e, autocommit=True)
s.execute("exec schema.ProcedureName 'param1', 'param2'")
SQLAlchemy log output:
INFO:sqlalchemy.engine.base.Engine:exec schema.ProcedureName 'param1',
'param2'
INFO:sqlalchemy.engine.base.Engine:()
Also I tried to manually begin transaction and commit after procedure
execution:
from sqlalchemy.engine import create_engine
from sqlalchemy.orm import create_session
e = create_engine('mssql+pyodbc://user:password@localhost/db')
s = create_session(bind=e, autocommit=True)
s.begin()
s.execute("exec schema.ProcedureName 'param1', 'param2'")
s.commit()
SQLAlchemy log:
INFO:sqlalchemy.engine.base.Engine:BEGIN (implicit)
INFO:sqlalchemy.engine.base.Engine:exec schema.ProcedureName 'param1',
'param2'
INFO:sqlalchemy.engine.base.Engine:()
INFO:sqlalchemy.engine.base.Engine:COMMIT
Commit seems to be done, but again no data written to database.
When using raw pyodbc with autocommit connection option, everything is
ok, data is successfully written to db:
import pyodbc
c = pyodbc.connect("DRIVER={SQL Server}; SERVER=localhost;
DATABASE=db; UID=user; PWD=password", autocommit=True)
c.execute("exec schema.ProcedureName 'param1', 'param2'")
What should I do solve this problem?
Thank you.
--
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.