mkleehammer / pyodbc

Python ODBC bridge
https://github.com/mkleehammer/pyodbc/wiki
MIT No Attribution
2.88k stars 561 forks source link

Connection is busy with results for another command (0) (SQLExecDirectW) #1333

Closed soujanyat closed 3 months ago

soujanyat commented 3 months ago

Please first make sure you have looked at:

Environment

Issue

sqlalchemy.exc.DBAPIError: (pyodbc.Error) ('HY000', '[HY000] [Microsoft][ODBC Driver 17 for SQL Server]Connection is busy with results for another command (0) (SQLExecDirectW)'

SQLAlchemy - 1.4.52 zope.sqlalchemy - 3.1 z3c.sqlalchemy = 2.1.1 No of Threads = 4

We are working on SQLAlchemy version up gradation project from version 1.3.x to 1.4.52 on ZOPE Framework. Post upgrade started getting Connection busy error and unable to access the application. We need your help to understand the issue and solution.

Thank You,

v-chojas commented 3 months ago

Try adding MARS_Connection=Yes to your connection string.

soujanyat commented 3 months ago

Try adding MARS_Connection=Yes to your connection string.

Thank you @v-chojas yes, we have tested with MARS_Connection=Yes connection string. Connection busy error is resolved however faced application slowness more than thrice the execution time of each APIs.

Is there a way to handle it without MARS_Connection or handle slowness

v-chojas commented 3 months ago

It sounds like your application is attempting to use multiple active resultsets, so you'll need to figure out how to change it to not do that. Unless MARS is enabled, the driver can only process one query at a time on a connection.