简体   繁体   English

pyodbc 锁表,运行时间过长

[英]pyodbc locks tables and takes too long to run

I have a python script to download files from an SFTP site to a local folder and then run a stored procedure using the downloaded file.我有一个 python 脚本,可以将文件从 SFTP 站点下载到本地文件夹,然后使用下载的文件运行存储过程。 The first aspect runs fine.第一个方面运行良好。 But then the execution of the stored procedure causes a lock on other tables on the SQL server - returns "Timeout expired" error.但是随后存储过程的执行导致 SQL 服务器上其他表的锁定 - 返回“超时过期”错误。 The procedure has been running for an hour and half.该程序已经运行了一个半小时。

This is the syntax I used for the execution of the stored procedure in case anybody was wondering:这是我用于执行存储过程的语法,以防有人想知道:

conn = pyodbc.connect('DRIVER={SQLServer};SERVER=localhost;DATABASE=Db;UID=myid;PWD=mypwd')
cursor = conn.cursor()

cursor.execute("""exec SP_Upsert_Y ?""",sfile)
cursor.commit()

我有同样的问题,我解决了将参数autocommit=True添加到连接字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM