Why is the (NTEXT) column in my MSSQL SELECT truncated at 4096k

When using a SELECT statement to query data from Microsoft SQL Server you may find that a “large data” or BLOB datatype column (NTEXT, TEXT, varchar(max), nvarchar(max), varbinary(max) or image) can be truncated probably to 4096k. Why is is this? And how can I fix it?

Firstly this is not an issue with Iguana, as Iguana places no limits on string lengths. Therefore the error must be with the data returned by the database.

Note: This FAQ assumes that you are familiar with SQL Server.

From reading Microsoft documentation about these datatypes, the following occurs:

  1. The “large data” column is bound to a program variable when you make a SELECT query
  2. By default this program variable is 4096k in length, as specified by TEXTSIZE setting (default = 4096k)
  3. You can set the length using the @@TEXTSIZE system function
  4. This applies when you use an API such as ADO, OLE DB, or ODBC

Result: When you query an NTEXT (or other “large data”) field the amount of data is restricted/truncated the to the length specified in TEXTSIZE (default = 4096k).

Solution: Use @@TEXTSIZE to increase the length so that all of the data in your field is returned.

Why not just return all the data by default? Performance! Many BLOB fields are mostly empty, TEXTSIZE allows you retrieve only the part you need. As opposed to sending mostly blank data in the field and greatly increasing network/processing overhead (remember these fields are able to store a huge amounts of data, so you could easily increase overheads by hundreds or thousands of times).

More Information

Leave A Comment?

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.