Linq, xml, and 2033 characters

R

R Dorris

I have a sp in sql2005 that uses the for xml path statement that I'm trying
to call using Linq to Sql. I've setup the sp in the datacontext and have it
returning a class that has one property of type string. When my code calls
the sp, I'm only getting back the first 2033 characters of the xml.... that's
no good. I've tried changing the return class to have a property of type
XDocument, but that fails too because the returned xml only has the first
2033 characters and therefore is not a valid xml document. Any ideas? thanks.
 
J

Jon Skeet [C# MVP]

R Dorris said:
I have a sp in sql2005 that uses the for xml path statement that I'm trying
to call using Linq to Sql. I've setup the sp in the datacontext and have it
returning a class that has one property of type string. When my code calls
the sp, I'm only getting back the first 2033 characters of the xml.... that's
no good. I've tried changing the return class to have a property of type
XDocument, but that fails too because the returned xml only has the first
2033 characters and therefore is not a valid xml document. Any ideas? thanks.

See http://aspnetresources.com/blog/executescalar_truncates_xml.aspx

It doesn't solve the LINQ aspect, but it might explain a bit about why
it's happening.
 
R

R Dorris

So it looks like looping/concatenating the results will fix my problem. I
guess I could then parse the string into an XDocument and make this whole
thing a method in my partial class for the return class. BUT, is there a
better way? If I want xml from the sql server, is there a better way to
retrieve it than using Linq to Sql? thanks for the help.
 
P

Peter Duniho

R Dorris said:
I have a sp in sql2005 that uses the for xml path statement that I'm
trying
to call using Linq to Sql. [...] When my code calls
the sp, I'm only getting back the first 2033 characters of the xml.
[...]

See http://aspnetresources.com/blog/executescalar_truncates_xml.aspx

It doesn't solve the LINQ aspect, but it might explain a bit about why
it's happening.

Actually, looking in the comments reveals a solution that doesn't require
explicitly building a new string by looping with ExecuteXmlReader.
Instead, it uses a stored procedure that stores the XML result in an
intermediate SQL XML variable, and returns that instead.

See
http://aspnetresources.com/blog/executescalar_truncates_xml.aspx#cmt1715
(the 12th comment)

So maybe using that approach would allow it to work more smoothly with
LINQ.

Or maybe all of this is over my head, and it doesn't help at all. I'm not
really sure. :)

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top