MySql throwing different exceptions with 8 threads RRS feed

  • Question

  • So something weird has started happening in my program. So I have multiple threads queued up with ThreadPool.QueueUserWorkItem. Until recently each thread in the threadpool would receive a List<MyObject> from an array and each insert the list into my MySql database. Recent changes to the handling of the list forced me to create one big list containing all the small lists (am using List.AddRange). I then split this list into smaller parts and sent each part to the same insert thread from before. Now the everything works perfectly with 7 threads or less. My program originally was using 8 threads to perform everything since I recall reading something that threads should be 2 * number of cores.

    Now when I run the program with 8 threads it starts throwing all kinds of MySqlExceptions which just seem to be thrown at random.  Example: All threads query a certain table that is never changed. Some threads will return the select * from table fine, while 1 random thread will suddenly say the table doesn't exist or that my DataTable is empty which is impossible since it's the same table and query. I've had all kinds of other exceptions such as OpenDataReader, Connection must valid and open, NullReferenceException when trying to close the Connection etc..

    Note: Each thread holds a separate connection to the database and therefore shouldn't be conflicting with each other.

    I'm not sure about pasting the code here since the code is pretty long. Plus I'm not so sure its something with my code since as I stated the problem arises when I use 8 threads or more. I don't want to take the easy road and just use 7 threads since there might be something underneath that I have no clue about that will cause problems in the future when I implement extra changes. I can edit my question accordingly if anyone asks me to show specific pieces.

    Thursday, May 31, 2012 10:51 AM


  • Hi,

    Since you are using MySQL db which is a 3rd party software, I cannot further research it deeply.  Could you please first consult the issue at MySQL forum http://forums.mysql.com/ to narrow down the issue?  If the problem is not at the db side and instead it's at .NET side, please follow up on this issue and we will continue to help you. 

    Have a nice weekend!


    Michael Sun [MSFT]
    MSDN Community Support | Feedback to us

    • Proposed as answer by Mr. Wharty Wednesday, June 6, 2012 1:55 AM
    • Marked as answer by Mr. Wharty Tuesday, June 12, 2012 1:38 AM
    Saturday, June 2, 2012 6:16 AM