ctds icon indicating copy to clipboard operation
ctds copied to clipboard

_tds.OperationalError: Received an invalid column length from the bcp client for colid...

Open gizmo93 opened this issue 5 years ago • 3 comments

When trying to bulk insert a String into a VARCHAR(MAX), NVARCHAR(MAX) field, we get this error message.

CTDS version: 1.11.0 FreeTDS version: 1.00.80 Python 3.7 Windows 10 64 bit

Example:

CREATE TABLE dbo.Test ( Id INT NOT NULL IDENTITY(1,1) PRIMARY KEY, FancyCol INT NOT NULL, [Value] NVARCHAR(MAX) )

CREATE TABLE dbo.Test2 ( Id INT NOT NULL IDENTITY(1,1) PRIMARY KEY, FancyCol INT NOT NULL, [Value] NVARCHAR(4000) )

Code to reproduce (sorry, really had problems to get the code properly formatted inside the Github Editor) test.txt

gizmo93 avatar Feb 19 '20 11:02 gizmo93

If I'm understanding correctly, you're reporting the behavior documented here: https://zillow.github.io/ctds/bulk_insert.html#text-columns

As far as I know, this is a deficiency in FreeTDS' implementation of BUILK INSERT

joshuahlang avatar Feb 20 '20 07:02 joshuahlang

Hey, there are no problems with "normal" VARCHAR/NVARCHAR columns, they work as expected, if I wrap them in ctds.VarChar(). Problem seems to be only when trying to BULK INSERT into a VARCHAR/NVARCHAR (MAX) column. Is there any solution / workaround for this?

gizmo93 avatar Feb 20 '20 08:02 gizmo93

Avoid varchar/nvarchar (max). Use ntext instead.

kafran avatar Apr 27 '20 03:04 kafran