]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Add LongAsMax note to mssql+pyodbc dialect docs
authorGord Thompson <gord@gordthompson.com>
Fri, 4 Mar 2022 18:13:14 +0000 (11:13 -0700)
committerGord Thompson <gord@gordthompson.com>
Fri, 4 Mar 2022 18:14:03 +0000 (11:14 -0700)
Change-Id: I4491b188bae49ac615f8691dd9b7a8a341428ce7

lib/sqlalchemy/dialects/mssql/pyodbc.py

index 0951f219b369e7f9e3e8f2110036eb961867a061..530a0a48096e29108faede74fee4dc1b8272a407 100644 (file)
@@ -179,6 +179,33 @@ at both the pyodbc and engine levels::
         isolation_level="AUTOCOMMIT"
     )
 
+Avoiding sending large string parameters as TEXT/NTEXT
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+By default, for historical reasons, Microsoft's ODBC drivers for SQL Server
+send long string parameters (greater than 4000 SBCS characters or 2000 Unicode
+characters) as TEXT/NTEXT values. TEXT and NTEXT have been deprecated for many
+years and are starting to cause compatibility issues with newer versions of
+SQL_Server/Azure. For example, see `this
+issue <https://github.com/mkleehammer/pyodbc/issues/835>`_.
+
+Starting with ODBC Driver 18 for SQL Server we can override the legacy
+behavior and pass long strings as varchar(max)/nvarchar(max) using the
+``LongAsMax=Yes`` connection string parameter::
+
+    connection_url = sa.engine.URL.create(
+        "mssql+pyodbc",
+        username="scott",
+        password="tiger",
+        host="mssqlserver.example.com",
+        database="mydb",
+        query={
+            "driver": "ODBC Driver 18 for SQL Server",
+            "LongAsMax": "Yes",
+        },
+    )
+
+
 Pyodbc Pooling / connection close behavior
 ------------------------------------------