Bug #30588 System.FormatException for Different Fields
Submitted: 23 Aug 2007 8:52 Modified: 15 Dec 2007 9:04
Reporter: Rene MT Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:5.0.8.0 OS:Microsoft Windows (XP Pro SP2)
Assigned to: CPU Architecture:Any

[23 Aug 2007 8:52] Rene MT
Description:
This seems to be one of the problems that aren't easily to reproduce... But however: Here is the description:

In a ASP.NET web application I'm using a MySqlDataReader to fetch a complete table with approx. 33,000 rows from a remote server. The fetching functionality runs asynchronously in a separate process. The table contains rows of type UInt, Byte and Decimal among others. After a while - one can't say exactly when - I got System.FormatExceptions from the connector when it tries to read the value of some field.

The exception occures for example in MySqlDecimal.ReadValue, or in MySqlUInt32.ReadValue, or others, when they try to parse the data read from stream by using DecimalParse(s, CultureInfo.InvariantCulture), or UInt32.Parse(stream.ReadString(length), CultureInfo.InvariantCulture).

The reason for this is, that the stream returned does contain only NULL bytes from a certain time on. So if the "real" field contains i.e. "10201" the buffer contains "102\0\0". Or even only NULL bytes. That System.Decimal (or even other types) are unable to parse this value seems clear. The interesting question is: Why does the stream reader return the invalid values? I don't get an exception or something before, it just seems the data deleivered from the remote server to the stream get corrupted. If I take a look at the DB with PHPMyAdmin, or just select some data from the table instead of fetching all, everything works well.

May it be possible that the connection to the database gets closed - and the connector doesn't recognize this? Maybe because of a connection timeout or something?

How to repeat:
Good question... Take a large table and try to fetch all rows by using a MySqlDataReader.
[30 Aug 2007 8:24] Rene MT
As I saw just now there is a little mistake in my description: The fetching function does not run in a different PROCESS, but in a different THREAD.

Regards,
ReneMT
[15 Nov 2007 9:04] Tonci Grgin
Hi Rene and thanks for your report. Sorry for the delay in processing.

I believe we fixed some similar problem recently. Can you please try version available at http://downloads.mysql.com/snapshots/mysql-connector-net-5.0/mysql-connector-net-5.0.9-200... and inform me of result?
[22 Nov 2007 22:42] Kevin Kopto
Hi,
I have a similar problem for 2 days now and finally stumbled over this post.

I cannot easily reproduce the exception, either. In my case I am reading data from a table with approx. 3.7 million records and the exception is thrown in MySqlDataReader.Read() and is of type System.FormatException.
I re-ran my app several times in the same environment now and it crashes randomly with that exception; sometimes after some thousand records, sometimes almost at the end beyond 2.9 million records read.
I was not able yet to trace the exception back so detailed, but i guess it's the same thing, because i also run my code within a thread and - very seldom - i get another exception: connection unexpectedly terminated.
To verify, that it is not a network problem i ran the code directly on the mysql  server machine with same results.
I will try to provide more details tomorrow but i cannot provide a test case as the exception comes really at random.
The sql statement in question returns less than 20 columns (mostly varchar, an int, two dates) and has one parameter but i'll give details tomorrow.

to be continued...

Kevin
[23 Nov 2007 8:05] Tonci Grgin
Rene & Kevin, please attach small but complete test case along with DDL/DML script that produces this error every time it is run. If one looks at what you provided me with so far the description would be:
 Take table with "various" fields containing unknown data having 10k to 10M rows to fetch via MySqlDataReader  in several threads, error *might* occur.
Does it sound reasonable to you that I leave everything and start writing test environment for this? If the problem is serious as severity suggests I think that the least you can do is provide me with test case. If problem is solved, I believe there are a lot of people who would be interested in solution you've found.
[16 Dec 2007 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".