Getting System.Byte[] In Your MySql Query Results Through Connector v5.2.5

by Marvin 30. March 2009 07:39

This is a little thing, but I ran into it again today, forgot how I fixed it before, and had to figure it out again.  To save myself the grief (and maybe someone else), I am posting the solution here.  I had a query that worked fine when I ran it from MySql Administrator, but when I ran it in my ASP.NET application using the .NET Connector v5.2.5, I was getting System.Byte[] values. 

Specifically, I had this query:

SELECT CONCAT('med: ',m.`medication_name`,', for ', c.`weight`, ' ', c.`units`,', ', c.`age`,' ', c.`case_name`) as `case_desc`
FROM `cases` c, `medications` m, `questions` q WHERE q.case_id=c.case_id AND q.medication_id=m.medication_id AND q.status=100;

It returned exactly what I wanted if I ran it in MySql Administrator.  The results looked something like this:

case_desc
med: Amoxicillin, for 3 kg, 1-month-old infant
med: Prednisone, for 3 kg, 1-month-old infant
med: prednisolone, for 3 kg, 1-month-old infant
med: Amoxicillin-Clavulanate, for 3 kg, 1-month-old infant
med: Keppra, for 3 kg, 1-month-old infant
med: Acetaminophen, for 3 kg, 1-month-old infant

But, when I hooked this table up in my asp.net application, the page was displaying "System.Byte[]" in place of "med:Amoxicillin...etc.".  I found other examples of this type of behavior reported on the mysql bug site here:

http://bugs.mysql.com/bug.php?id=26993

http://bugs.mysql.com/bug.php?id=37042

Reggie Burnett, who is the team lead at MySql for development on the .NET connector, recommends using the .GetString() method on the data reader to work around this issue.  In my particular implementation, I was separating the data reader from the query (sounds weird, i know), so I went with the other suggestion, which is to add "respect binary flags=false" into my connection string which reverts back to pre 5.1 behavior and fixes the problem.

Currently rated 5.0 by 4 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Comments

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



About the author

I am a junior-level C# .NET developer living in Nashville, TN.  I'm currently working in biomedical informatics, developing a web service, a MySql database, and a web application.  Every week or so, I spend hours trying to figure out how to do something, and after I find the solution, I really want to make sure I don't go through that exercise again.  I love to write.  It helps me to remember things.  So, I use this blog as a way to document those painful lessons as I learn them.  It has already helped me to be able to refer back to them.  I hope some of these will save someone else some time as well.