String data, right truncation while using fast executemany with pyodbc

Viewed 4962

I am struggling with

pyodbc.ProgrammingError: ('String data, right truncation: length 636 buffer 510', 'HY000')

while using executeMany() with __crsr.fast_executemany = True. When I remove this line everything works fine.

I am using pyodbc (4.0.30) and MSSQL with ODBC Driver 17 for SQL Server.

My database table looks like 4 columns and each of them is varchar(255).

I already to add this line: crsr.setinputsizes([(pyodbc.SQL_WVARCHAR, 50, 0)]) and add UseFMTOnly=yes to connection string but it didn't work.

Could you guys help me, please? I am already tired of that.

1 Answers

Check the ODBC Driver you are using in your pyodbc connection string, if it is an old version, errors could be misleading, use for example: driver="{ODBC Driver 17 for SQL Server}"

instead of: driver="{SQL Server}"

Related