l******9 发帖数: 579 | 1 【 以下文字转载自 Database 讨论区 】
发信人: light009 (light009), 信区: Database
标 题: run SQL stored procedure from python
发信站: BBS 未名空间站 (Sat Aug 2 20:53:01 2014, 美东)
I need to run a SQL server 2008 R2 stored procedure from Eclipse pydev with
python 3.2 on win 7. If I run the stored procedure from management studio,
it works well.
But, if I run it from ptython , it does not work.
sql_str_test = """
DELETE FROM [my_db].[dbo].[my_table] -- this line works
EXEC [my_db].[dbo].[my_store_procedure] -- but this line
does not work, no run-time error message, but no results generated
"""
sql_str_connect = "DRIVER={SQL server};SERVER={my_server};DATABASE={my_db};
UID=my_id;PWD=my_table"
cnxn = pyodbc.connect(sql_str_connect)
cursor_test = cnxn.cursor()
cursor_test.execute(sql_str_test)
cnxn.commit()
If I run
DELETE FROM [my_db].[dbo].[my_table]
EXEC [my_db].[dbo].[my_store_procedure]
from SSMS, it works.
Thanks |
|