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

  • Home
  • SEARCH
  • 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 168231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:24:59+00:00 2026-05-11T12:24:59+00:00

I have SQL table that has a varchar(8) column that occasionally has binary data

  • 0

I have SQL table that has a varchar(8) column that occasionally has binary data in it. (0x01, 0x02, etc…). (Changing the format or the content of the column isn’t an option.)

When I go into the SQL Server 2005 Management Studio and run the query:

select *   from mytable   where clientID = 431620  for xml auto 

I get useful results. Notice how proc_counts is encoded:

<mytable clientID='431620' recno='19014235' pdate='2008-03-04T00:00:00'    proc_counts='&#x1;&#x1;&#x2;&#x1;' otherstuff='foobar'     date='2008-02-17T00:00:00'/> 

Perfectly valid XML, AFAIK. Now when I actually write C# code to read this row, I’m getting an exception throw during ReadOuterXml:

SqlCommand cmd = new SqlCommand('select * from testing xml auto', connection); using (XmlReader xrd = cmd.ExecuteXmlReader()) {     xrd.Read();     while (xrd.ReadState != ReadState.EndOfFile)     {         string s = xrd.ReadOuterXml();         records.Add(s);     } } 

This throws: XmlException was unhandled. ”, hexadecimal value 0x01 is an invalid character. I want the XML from above, but don’t have sufficient Google-fu to figure out why I’m not getting it. Suggestions?


To create a table with this kind of data, this Transact SQL code works in SSMS:

create table testing (clientid int, proc_counts varchar(8)); insert into testing values (1, 'normal'); insert into testing values (2, char(65) + char(1) + char(65)); select * from testing for xml auto; 

Update: Post-mortem and workaround

Dommer’s probably right, that it’s the Normalization property in the XmlTextReader that’s giving me problems. The thing is (as you can see from the comments) I found it pretty much impossible to go from a (SqlCommand).ExecuteXmlReader() to anything that will let me go near the Normalization property of an XmlTextReader. Oftentimes the Microsoft documentation on this was contradictory or just plain wrong.

So I settled on a workaround. If I simply use an SqlDataReader to soak up the output everything is fine. The XML looks perfect and parses quite nicely.

StringBuilder sb = new StringBuilder(); using(SqlDataReader dr = cmd.ExecuteReader()) {     while(rdr.Read())         sb.Append((string)rdr[0]); } 
  • 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. 2026-05-11T12:24:59+00:00Added an answer on May 11, 2026 at 12:24 pm

    It’s to do with the XmlTextReader.Normalization property. This property is set to false when you explicitly create an XmlTextReader, so the ‘invalid’ characters are decoded. When the XmlTextReader is created implicitly, Normalization is set to true.

    The property is discussed here:

    http://msdn.microsoft.com/en-us/library/system.xml.xmltextreader.normalization.aspx

    If you do the processing ‘manually’ – i.e. create an XmlTextReader – I think you’ll avoid the error.

    UPDATE:

    Changes in the more recent versions of the framework mean that ‘XmlReaderSettings.CheckCharacters = false’ may be the way to go in ASP.NET 2.0+. An XmlReaderSettings object can be passed to XmlReader.Create.

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

Sidebar

Ask A Question

Stats

  • Questions 114k
  • Answers 114k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What you're after is a many to many relationship between… May 11, 2026 at 10:16 pm
  • Editorial Team
    Editorial Team added an answer The "Access Denied" is expected behavior given what you're attempting… May 11, 2026 at 10:16 pm
  • Editorial Team
    Editorial Team added an answer I used the following algorithm to solve my problem: Start… May 11, 2026 at 10:16 pm

Related Questions

I need some advice in tackling a query. I can handle this in a
I need to insert records into a table that has no primary key using
I have a table that has ntext field. MSDN says that ntext is deprecated
EDIT : To people building tagging systems. Don't read this. It is not what

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.