Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find data type 'ntext' error in Azure SQL Data Warehouse

I am running a UPDATE statement against Azure SQL Data Warehouse using pyodbc:

cursor.execute(
  "UPDATE dbo.test SET desc = ? WHERE id = ?", desc, id
)

This works fine when desc value is simple. But when the value of desc is more complex (longer text), executing the above spits out the following error:

pyodbc.ProgrammingError: ('42000', "[42000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]104220;
Cannot find data type 'ntext'. (100000) (SQLExecDirectW)")

I thought escaping will solve any issues but it didn't. Any idea/insight?

like image 984
kee Avatar asked Oct 22 '25 10:10

kee


2 Answers

The new parameter - 'LongAsMax' in connection string that was added for ODBC Driver 18, helped me to solve similar issue. It works for me even without using cursor.setinputsizes:

connectionString = f'DRIVER={{ODBC Driver 18 for SQL Server}};SERVER={HOST};DATABASE={DB};UID={UID};PWD={PWD};Authentication=ActiveDirectoryPassword;LongAsMax=yes;'
like image 159
Vladislav Kabachny Avatar answered Oct 26 '25 02:10

Vladislav Kabachny


Could you try this:

cursor.execute(
  "UPDATE dbo.test SET desc = CAST(? AS NVARCHAR(MAX)) WHERE id = ?", desc, id
)

I guess the pyodbc is somehow converting the large string to ntext.

If this doesn't help, check the following github link - it might help you as it is explain that if:

you're using an old SQL Server (WDAC) driver which treats nvarchar as ntext and that's why you're experiencing the issue because there's no reference to ntext type inside django-pyodbc-azure

like image 45
gotqn Avatar answered Oct 26 '25 02:10

gotqn