From 209b1a7d3c01dfd281b536fbf9e918d7efd30985 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Sun, 5 Jul 2020 10:28:20 -0400 Subject: [PATCH] Document pyodbc built-in pooling PyODBC apparently pools connections by default and this is a module-wide setting only. Documenent that this happens and how to disable it. Fixes: #5440 Change-Id: I415bda7beb2211c66991b6c804b0ddb4d79e427f (cherry picked from commit 9204b6610c9667ba2e4f73440339d2f520631777) --- lib/sqlalchemy/dialects/mssql/pyodbc.py | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/lib/sqlalchemy/dialects/mssql/pyodbc.py b/lib/sqlalchemy/dialects/mssql/pyodbc.py index b2571de4f6..26c5d3d545 100644 --- a/lib/sqlalchemy/dialects/mssql/pyodbc.py +++ b/lib/sqlalchemy/dialects/mssql/pyodbc.py @@ -70,6 +70,32 @@ illustrated below using ``urllib.parse.quote_plus``:: engine = create_engine("mssql+pyodbc:///?odbc_connect=%s" % params) +Pyodbc Pooling / connection close behavior +------------------------------------------ + +PyODBC uses internal `pooling +`_ by +default, which means connections will be longer lived than they are within +SQLAlchemy itself. As SQLAlchemy has its own pooling behavior, it is often +preferable to disable this behavior. This behavior can only be disabled +globally at the PyODBC module level, **before** any connections are made:: + + import pyodbc + + pyodbc.pooling = False + + # don't use the engine before pooling is set to False + engine = create_engine("mssql+pyodbc://user:pass@dsn") + +If this variable is left at its default value of ``True``, **the application +will continue to maintain active database connections**, even when the +SQLAlchemy engine itself fully discards a connection or if the engine is +disposed. + +.. seealso:: + + `pooling `_ - + in the PyODBC documentation. Driver / Unicode Support ------------------------- -- 2.47.2