By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,781 Members | 1,432 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,781 IT Pros & Developers. It's quick & easy.

Trouble with Response.Write([long string here])

P: 32
(After thinking about it, maybe this should have been posted in the .NET forum...)

Hi,

I have a stored procedure in SQL Server that sends me a 3000+ char pre-formatted XML string. I use "FOR XML EXPLICIT" and it works really well when I do the query in Management Studio.

But, when it comes to output, something goes wrong. My output code is very basic, I don't know if it could be better. I use ExecuteScalar since the procedure returns the pre-formatted XML string in a 1X1 "table".

Response.Write("<?xml version=""1.0"" encoding=""UTF-8"" ?>")
Response.Write("<Listelivraisons>") 'This is the "root element
Response.Write(db.ExecuteScalar(cmdCalendrier_xml) )
Response.Write("</Listelivraisons>") 'End of the root

I can see string but the later half (or so) of it is missing.

Actually, if I look at the source of my XML page with IE, I can see that the file ends with :
<Livraison id="6"><JOB_NO>68756</JOB_NO><CUST_C</Listelivraisons>

I really don't know why. When I execute the query with Management Studio, the "livraison" id 6 is complete and there's even another record of two after it. But it just won't show if I Response.Write.

I tried using DataReader and other things instead of ExecuteScalar, it didn't change a thing. I tried using Response.Output.Write, with no dice.


Should I be using a buffer or something??
Feb 1 '08 #1
Share this Question
Share on Google+
4 Replies


CroCrew
Expert 100+
P: 564
Hello myth0s,

It somewhat sounds like you need to flush out the response. Are you looping your “response.write”s? If you are then try flushing between loops using the “response.flush” command.

Sorry for the short possible answer. But, I will look for a better one.

Hope this helped out~
Feb 1 '08 #2

P: 32
Hello myth0s,

It somewhat sounds like you need to flush out the response. Are you looping your “response.write”s? If you are then try flushing between loops using the “response.flush” command.

Sorry for the short possible answer. But, I will look for a better one.

Hope this helped out~
No, I'm not looping Response.Write since ExecuteScalar returns the string directly. (ExecuteScalar is "designed" to return the value of the first row of the first column, instead of a DataSet).

I have added Response.flush nonetheless, hoping it would help, but no. I have a vague felling that my string is too long or something. I used MS Word to count and the string always cuts off after exactly 2033 characters.....
Feb 1 '08 #3

P: 32
No, I'm not looping Response.Write since ExecuteScalar returns the string directly. (ExecuteScalar is "designed" to return the value of the first row of the first column, instead of a DataSet).

I have added Response.flush nonetheless, hoping it would help, but no. I have a vague felling that my string is too long or something. I used MS Word to count and the string always cuts off after exactly 2033 characters.....
Now that I have noticed that my string cuts off after 2033 characters, I have found this : http://www.informit.com/articles/article.aspx?p=25339&seqNum=4

I will let you know if it works :/
Feb 1 '08 #4

P: 32
Now that I have noticed that my string cuts off after 2033 characters, I have found this : http://www.informit.com/articles/art...25339&seqNum=4

I will let you know if it works :/
Should anyone find this page using google while searching why in the world their string was being trimmed down (incomplete data, missing data). Apparently, even if you use ExecuteScalar, the string is cut to 2033 characters.

The solution is in the link above. It works great with SQL Server returning "FOR XML" data.

I have changed my output code to
Expand|Select|Wrap|Line Numbers
  1. Dim db As Database = DatabaseFactory.CreateDatabase("SQLServer") 'I am using Enterprise Library from Microsoft
  2.         Dim cmdCalendrier_xml As DbCommand = db.GetStoredProcCommand("production.lv_calendrier_xml")
  3.         db.AddInParameter(cmdCalendrier_xml, "@date_activite_min", DbType.Date)
  4.  
  5.         Dim buffer As System.Text.StringBuilder = New System.Text.StringBuilder()
  6.         buffer.Append("<?xml version=""1.0"" encoding=""UTF-8"" ?>")
  7.         buffer.Append("<Listelivraisons>")
  8.  
  9.         Dim dataReader As IDataReader = db.ExecuteReader(cmdCalendrier_xml)
  10.  
  11.         While (dataReader.Read())
  12.             buffer.Append(dataReader.GetString(0))
  13.         End While
  14.  
  15.         buffer.Append("</Listelivraisons>")
  16.         Response.Write(buffer.ToString)
Thanks for your help, CroCrew
Feb 1 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.