0

I have the following C# Code:

MySqlDataReader myData;
MySqlCommand cmd = new MySqlCommand();

string SQL;
SQL = "SELECT * FROM StoredFile WHERE StoredFileID = [PRIMARY_KEY] LIMIT 1";

cmd.Connection = new MySqlConnection(DbContext.Database.Connection.ConnectionString);
cmd.Connection.Open();
cmd.CommandText = SQL;

myData = cmd.ExecuteReader();

if (!myData.HasRows)
    return null;

myData.Read();

StoredFile rtn = new StoredFile();
rtn.StoredFileID = (long)myData["StoredFileID"];
rtn.Filename = (string)myData["Filename"];
rtn.MIMEType = (string)myData["MIMEType"];
rtn.Data = (byte[])myData["Data"];
rtn.SYS_INS_USER = (string)myData["SYS_INS_USER"];
rtn.SYS_INS_ID = (long)myData["SYS_INS_ID"];
rtn.SYS_INS_DT = (DateTime)myData["SYS_INS_DT"];
rtn.SYS_UPD_USER = (string)myData["SYS_INS_USER"];
rtn.SYS_UPD_ID = (long?)myData["SYS_INS_ID"];
rtn.SYS_UPD_DT = (DateTime?)myData["SYS_INS_DT"];
rtn.SYS_ACTIVE = (bool)myData["SYS_ACTIVE"];
var o = myData["PrivateNotes"];
if (o != DBNull.Value)
    rtn.PrivateNotes = (string)o;

myData.Close();
myData.Dispose();

cmd.Connection.Close();
cmd.Dispose();

return rtn;

Using C#, when I use "5" for the [PRIMARY_KEY], MySQL returns the record. When I use "10" for the [PRIMARY_KEY], MySQL doesn't return a record

Using phpMyAdmin, the select statement returns both records. Also in phpMyAdmin I can download the blob data and all is fine with it.

Records from phpMyAdmin:

image

It seems like anything over a few KB's are not returned when trying it through C#. Is there a setting or something in C# / MySQL Library / etc that prevents the select from returning a "large" BLOB field?

Lews Therin
  • 3,707
  • 2
  • 27
  • 53
Vee
  • 73
  • 1
  • 9
  • 1
    Your code blocks need cleaned up with `using` blocks. Off-topic, but still. – Drew Aug 11 '16 at 17:42
  • How about Skeet's GetBytes [answer](http://stackoverflow.com/a/7703111) ? – Drew Aug 11 '16 at 17:46
  • what happens when you remove the LIMIT Selecting using the Where IN should be enough.. – MethodMan Aug 11 '16 at 17:47
  • Have you looked into `max_allowed_packet`? – Uueerdo Aug 11 '16 at 18:22
  • It could very well have to do with `max_allowed_packet` as suggested - its nothing fundamentally wrong with MySQL. You could also forego those casts using the DataReader extensions `GetInt32()`, `GetDate` etc – Ňɏssa Pøngjǣrdenlarp Aug 11 '16 at 19:12
  • Hey Drew, I don't get any record back for the "10" ID ... The "HasRows" is false for the 10 id. HasRows is true for the "couple of KB" ones and GetBytes and "(byte[])myData["Data"]" yield the same result when I tried it. – Vee Aug 11 '16 at 19:25
  • Hey MethodMan, I tried removing the limit but still have the same result. – Vee Aug 11 '16 at 19:25
  • Hey Uueerdo and Plutonix, I'm able to upload the file(s) through C# and run an insert statement to store the file so I think max_allowed_packet is set high enough. Also if that were too low, wouldn't phpMyAdmin have the same problem for accessing the blob? – Vee Aug 11 '16 at 19:27
  • I ran show variables like 'max_allowed_packet' and it returned 4,194,304 – Vee Aug 11 '16 at 19:30
  • Vee, I haven't had to play with the setting myself; I just noticed the documentation mentioned there were server AND client settings. – Uueerdo Aug 11 '16 at 21:18
  • http://stackoverflow.com/a/38829952/267540 – e4c5 Aug 12 '16 at 01:28

0 Answers0