Wednesday, 15 April 2015

sql server - how can I get pyodbc to perform a "SELECT ... INTO" statement without locking? -



sql server - how can I get pyodbc to perform a "SELECT ... INTO" statement without locking? -

i'm trying re-create table in sql server, simple statement seems locking database when using pyodbc. here's code i'm trying:

dbcxn = db.connect(cxnstring) dbcursor = dbcxn.cursor() query = """\ select top(10) * production_data_adjusted production_data """ dbcursor.execute(query)

the lastly statement returns immediately, both linqpad , sql server management studio locked out of database afterwards (i seek refresh table lists). running sp_who2 shows linqpad/ssms stuck waiting pyodbc process. other databases on server seem fine, access database gets held up. way can these other applications resolve stalls closing pyodbc database connection:

dbcxn.close()

this exact same select ... into statement statement works fine , takes sec linqpad , ssms. above code works fine , doesn't lock database if remove into line. returns results if add together fetchone() or fetchall().

can tell me i'm doing wrong here?

call commit function of either cursor or connection after select ... into executed, example:

... dbcursor.execute(query) dbcursor.commit()

alternatively, automatic commit of transactions can specified when connection created using autocommit. note autocommit argument connect function, not connection string attribute, example:

... dbcxn = db.connect(cxnstring, autocommit=true) ...

sql-server pyodbc

No comments:

Post a Comment