Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. XmlException when uploading Image to database

XmlException when uploading Image to database

Scheduled Pinned Locked Moved C#
helpdata-structuresdatabasemysqldebugging
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    methodincharge
    wrote on last edited by
    #1

    I have a web service that will upload/retrieve images from a MySQL database. I am passing it an array of objects to signify multiple images (although I am only using one). Anyway when I get the binary array and try to execute oCmd.ExecuteNonQuery(); I get the following error:

    ', hexadecimal value 0x10, is an invalid character. Line 1, position 449.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Xml.XmlException: '', hexadecimal value 0x10, is an invalid character. Line 1, position 449.

    The code I use is as following: OdbcCommand oCmd = null; foreach(String name in names) { byte[] singleton = data[names.IndexOf(name)] as byte[]; oCmd = new OdbcCommand("INSERT INTO images (name,data,length,user) VALUES (?name,?data,?size,?user)",oCon); OdbcParameter p0 = new OdbcParameter("?name",OdbcType.VarChar,100); p0.Value = name; oCmd.Parameters.Add(p0); OdbcParameter p1 = new OdbcParameter("?data",OdbcType.Binary); p1.Value = singleton; OdbcParameter p2 = new OdbcParameter("?size",OdbcType.Int,20); p2.Value = singleton.Length; oCmd.Parameters.Add(p2); OdbcParameter p3 = new OdbcParameter("?user",OdbcType.VarChar,100); p3.Value = username; oCmd.Parameters.Add(p3); oCmd.ExecuteNonQuery(); } I am thinking maybe it's an issue with Encoding? Unfortunately I was never good at dealing with Encoding. Can anyone help?

    C 1 Reply Last reply
    0
    • M methodincharge

      I have a web service that will upload/retrieve images from a MySQL database. I am passing it an array of objects to signify multiple images (although I am only using one). Anyway when I get the binary array and try to execute oCmd.ExecuteNonQuery(); I get the following error:

      ', hexadecimal value 0x10, is an invalid character. Line 1, position 449.
      Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

      Exception Details: System.Xml.XmlException: '', hexadecimal value 0x10, is an invalid character. Line 1, position 449.

      The code I use is as following: OdbcCommand oCmd = null; foreach(String name in names) { byte[] singleton = data[names.IndexOf(name)] as byte[]; oCmd = new OdbcCommand("INSERT INTO images (name,data,length,user) VALUES (?name,?data,?size,?user)",oCon); OdbcParameter p0 = new OdbcParameter("?name",OdbcType.VarChar,100); p0.Value = name; oCmd.Parameters.Add(p0); OdbcParameter p1 = new OdbcParameter("?data",OdbcType.Binary); p1.Value = singleton; OdbcParameter p2 = new OdbcParameter("?size",OdbcType.Int,20); p2.Value = singleton.Length; oCmd.Parameters.Add(p2); OdbcParameter p3 = new OdbcParameter("?user",OdbcType.VarChar,100); p3.Value = username; oCmd.Parameters.Add(p3); oCmd.ExecuteNonQuery(); } I am thinking maybe it's an issue with Encoding? Unfortunately I was never good at dealing with Encoding. Can anyone help?

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      If your data is XML, then you need to put your image in a CDATA section, or you'll get this sort of an error. Christian Graus - Microsoft MVP - C++

      M 1 Reply Last reply
      0
      • C Christian Graus

        If your data is XML, then you need to put your image in a CDATA section, or you'll get this sort of an error. Christian Graus - Microsoft MVP - C++

        M Offline
        M Offline
        methodincharge
        wrote on last edited by
        #3

        How would I go about doing that if I am using SOAP to transport the data to and from the web service? Also I read that CDATA only makes the problem less likely (IE: if the string is terminated by ])> it will cause the section to end) and I figure that if I'm going to be using this just for images the liklihood of that would be pretty high. Any suggestions? I tried using Base64 encoding, but that gives the same error.

        C 1 Reply Last reply
        0
        • M methodincharge

          How would I go about doing that if I am using SOAP to transport the data to and from the web service? Also I read that CDATA only makes the problem less likely (IE: if the string is terminated by ])> it will cause the section to end) and I figure that if I'm going to be using this just for images the liklihood of that would be pretty high. Any suggestions? I tried using Base64 encoding, but that gives the same error.

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          methodincharge wrote: Also I read that CDATA only makes the problem less likely (IE: if the string is terminated by ])> it will cause the section to end) Yes, if you manage that three character set in your image, then you'd have a problem. The changes of that are 255*255*255 to 1, as far as I can see. methodincharge wrote: I figure that if I'm going to be using this just for images the liklihood of that would be pretty high Why ? methodincharge wrote: How would I go about doing that if I am using SOAP to transport the data to and from the web service? Put the CDATA tags around the image data before passing it to the SOAP layer, and remove them at the other end. Christian Graus - Microsoft MVP - C++

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups