ntext Question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Martin

    ntext Question

    Dear Group

    I admit, this might be a very ignorant question.

    BOL says about the ntext data type:
    Variable-length Unicode data with a maximum length of 2^30 - 1
    (1,073,741,823) characters.

    I've stored a string consisting of around 45.000 characters in a ntext
    field - done by copying the string in my txt document and pasting in
    Enterprise Manager.

    When I determine the datalength of the field in SQL Analyzer I get
    2046.
    Is this realistic? Is it bytes or the actual number of characters? It
    seems incrrect to me..

    Although, when I read the string with a DataReader based on a stored
    procedure and save it in a string variable in my VB.NET application,
    the string is truncated, although the variable can hold up to
    approximately 2 billion Unicode characters according to MSDN.

    I just wonder whether I've done something wrong or misunderstood
    something on the SQL server side that causes this problem.

    Thanks very much for your help!

    Martin
  • Erland Sommarskog

    #2
    Re: ntext Question

    Martin (theintrepidfox @hotmail.com) writes:[color=blue]
    > BOL says about the ntext data type:
    > Variable-length Unicode data with a maximum length of 2^30 - 1
    > (1,073,741,823) characters.
    >
    > I've stored a string consisting of around 45.000 characters in a ntext
    > field - done by copying the string in my txt document and pasting in
    > Enterprise Manager.
    >
    > When I determine the datalength of the field in SQL Analyzer I get
    > 2046.
    > Is this realistic? Is it bytes or the actual number of characters? It
    > seems incrrect to me..[/color]

    datalength() return the length in bytes, so it appears that only 1023
    characters made it to the table through Enterprise Manager. EM is
    poor tool for most of the functions it exhibits, and data entry is
    one of them. Apparently there is a limitation.

    If the document is only 46000 characters, you can write an insert
    statement for it in Query Analyzer. However, QA can only handle 64KB
    of text. I know, because I tried run an SQL statement with a 500 KB
    long XML string the other day... I was able to get that working by
    putting it all in a file with a third-party text editor, and run
    the file from the command-line tool OSQL.


    --
    Erland Sommarskog, SQL Server MVP, esquel@sommarsk og.se

    Books Online for SQL Server SP3 at
    Transform your business with a unified data platform. SQL Server 2019 comes with Apache Spark and Hadoop Distributed File System (HDFS) for intelligence over all your data.

    Comment

    • Martin

      #3
      Re: ntext Question

      Hi Erland
      Thanks very much for sharing your expertise.
      Have a nice day :-)

      M

      Comment

      Working...