XmlException when uploading Image to database
-
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? -
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?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++
-
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++
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.
-
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.
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++