Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6928505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:11:48+00:00 2026-05-27T11:11:48+00:00

Have a SQL command with FOR XML that returns a single long XML as

  • 0

Have a SQL command with FOR XML that returns a single long XML as SqlString. My problem is reading the long XML string into .NET C#.

The following only reads the first 2033 characters

    SqlDataReader rdr = command.ExecuteReader();
    if (rdr.HasRows)
    {
        rdr.Read();
        Debug.WriteLine(rdr[0].ToString().Length.ToString());
    }

I have also tried command.ExecuteScalar and rdr.GetString and still only get the first 2033 characters. I have changed the sort and it still truncates at 2033 so it is not likely caused by a bad character. Tried rdr.GetSqlXml and get an error message cannot cast SqlString to SqlCachedBuffer.

If I limit the SQL to return less than 2033 character I do get the complete valid XML. So I don’t think it is an XML parsing issue rather just a truncation. I don’t need any XML parsing – it is valid XML from the TSQL statement that I need as string.

How can I read the full XML (as text)?

The TSQL works.

    select top 10 docSVsys.sID, docSVsys.docID
      , (select top 10 value + '; '
          from docMVtext with (nolock) where docMVtext.sID = docSVsys.sID 
               and docMVtext.fieldID = '113'
          order by value FOR XML PATH('') ) as [To]
      from docSVsys with (nolock) 
      order by docSVsys.sID
      for xml auto, root('documents')

The FOR XML PATH provides what I need and fast. I tried a regular query and then generating the XML using Xdocument but performance is horrible with even more than 100 lines as it needs to search on sID to add the To. I guess I could write the concatenation as a SQL function to avoid the FOR XML AUTO but that query with the FOR XML is fast and provides the exact results I need. It is just how to retrieve the result?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:11:49+00:00Added an answer on May 27, 2026 at 11:11 am

    This is a known issue, see: http://support.microsoft.com/kb/310378

    Use ExecuteXmlReader instead. The underlying cause is that SQL breaks up the returned XML, so you need to read the reply differently. I’ve had the same issue in ADO using VBScript too.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have MS SQL Server stored procedure that returns XML (it uses SELECT with
I have an UPDATE sql command that modifies a Date/Time field in a particular
I have created a function that takes a SQL command and produces output that
We have an application that installs SQL Server Express from the command line and
I've come across a problem with modifying XML within SQL Server that doesn't seem
I have inserted xml into SQL Server 2005 through rich text field successfully, now
i have an ASP.net page that generates dynamic xml but the get statement of
I have a php script that parses XML files and creates a large SQL
Say I have a table called myTable. What is the SQL command to return
I have used an update command to update the whole table in an Sql

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.