简体   繁体   中英

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. 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. 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添加到连接字符串

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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