]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Document pyodbc built-in pooling
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 5 Jul 2020 14:28:20 +0000 (10:28 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 5 Jul 2020 14:29:29 +0000 (10:29 -0400)
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

index b2571de4f663c92bd9e82052f6074ab7cb493b30..26c5d3d545fd438e0476a3b8d4def65ff49d0427 100644 (file)
@@ -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
+<https://github.com/mkleehammer/pyodbc/wiki/The-pyodbc-Module#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 <https://github.com/mkleehammer/pyodbc/wiki/The-pyodbc-Module#pooling>`_ -
+    in the PyODBC documentation.
 
 Driver / Unicode Support
 -------------------------