I'm trying to insert a single row to a table that has a nvarchar(max)
column (say response) using python's pymssql
library.
The other columns are straightforward - one nvarchar(10) column, two nvarchar(30) columns, two date columns and one bigint column
I don't really have control over the length of the response string I get and as a result they can be of arbitrary length. Everywhere I've searched shows (e.g. What is the maximum characters for the NVARCHAR(MAX)?) that nvarchar(max)
can support up to a billion characters. However, the code I'm using seems to break at around the 130 million character mark.
Code:
import pymssql
from pathlib import Path
conn = pymssql.connect('server', 'user', 'password', 'db')
content = Path('file.txt').read_text()
print(len(content)) # 547031539
with conn.cursor() as cursor:
cursor.execute("Insert into table_name values (%s, %s, %s, %d, %s, %s, %s)", ('2020-05-21', '2023-03-27T20:51:50.221718', '2023-03-27T19:34:02.103253', 127671, content[:133_949_006], 'New', '2020-05-22'))
conn.commit()
Traceback:
---------------------------------------------------------------------------
MSSQLDatabaseException Traceback (most recent call last)
File src\pymssql\_pymssql.pyx:461, in pymssql._pymssql.Cursor.execute()
File src\pymssql\_mssql.pyx:1087, in pymssql._mssql.MSSQLConnection.execute_query()
File src\pymssql\_mssql.pyx:1118, in pymssql._mssql.MSSQLConnection.execute_query()
File src\pymssql\_mssql.pyx:1251, in pymssql._mssql.MSSQLConnection.format_and_run_query()
File src\pymssql\_mssql.pyx:1789, in pymssql._mssql.check_cancel_and_raise()
File src\pymssql\_mssql.pyx:1835, in pymssql._mssql.raise_MSSQLDatabaseException()
MSSQLDatabaseException: (20047, b'DB-Lib error message 20047, severity 9:\nDBPROCESS is dead or not enabled\n')
During handling of the above exception, another exception occurred:
OperationalError Traceback (most recent call last)
Cell In[126], line 2
1 with conn.cursor() as cursor:
----> 2 cursor.execute(Insert into table_name values (%s, %s, %s, %d, %s, %s, %s)", ('2020-05-21', '2023-03-27T20:51:50.221718', '2023-03-27T19:34:02.103253', 127671, content[:133_949_006], 'New', '2020-05-22'))
3 conn.commit()
File src\pymssql\_pymssql.pyx:479, in pymssql._pymssql.Cursor.execute()
OperationalError: (20047, b'DB-Lib error message 20047, severity 9:\nDBPROCESS is dead or not enabled\n')