Related Documentation Download this Manual Excerpts from this Manual


This page has moved or been replaced. The new page is located here:

Please update any bookmarks that point to the old page.

Download this Manual
User Comments
  Posted by Vladimir Vukanac on February 12, 2012
fs.Lenght is long.
Not compatible with UInt32.[], int, int)
requires int for buffer lenght.
  Posted by Gabriela Martinez Sanchez on February 29, 2012
The type of the variable FileSize is correct when assigning the return value of GetUInt32, but it makes conflicts in the GetBytes and in the Write methods, which only take integers. So you have to make that change in order to run the code.
  Posted by Rob Brahier on March 4, 2012
I just wanted to clarify what Gabriela and Vladimir are talking about for anyone new to MySQL or C#/VB.

Remember that the examples in this section are not meant to be dropped directly into production code. For one thing, anyone thinking of storing a file in a database should make sure the file is small enough to fit in the blob type you choose. If you don't then MySQL will either throw an error (SQL STRICT mode only) or truncate your file data and issue a warning.

The MEDIUMBLOB field used in these examples can hold 16,777,216 bytes of data (16MB). The MEDIUMBLOB field gets dumped into an array of bytes when we read it from MySQL, so the biggest array we could possibly need would also hold 16,777,216 bytes. With that in mind, the casts from a long value (fs.Length) to a UInt32 (FileSize)and finally to an int (in myData.GetBytes()) will never cause a problem here, because the number returned by fs.Length will always be lower than the maximum value of an int.

There are a number of issues that arise when working with large chunks of BLOB data. See section 10.4.3 "The BLOB and TEXT Types" for more gotchas, and good luck!
Sign Up Login You must be logged in to post a comment.