How do I retrieve more information about this bulk load error?

I’m attempting to bulk-load some data into a MySql server, using the MySqlBulkCopy class from the MySqlConnector library.

For the first table it works just fine. For the second table, it errors out, saying 0 out of 10 rows were written. (Using a small data set for testing purposes; real-world usage would involve a lot more rows than that.)

Debugging into the library code, I find that the warning count from the operation’s result is 30, and the affected row count is 0, but the library doesn’t do anything with those warnings. They’re never surfaced to the user-facing error message, and with the way the reply packet is basically just metadata, I suspect that some additional API call would be needed to retrieve the warnings.

Assuming that I have full access to both the MySql server and the source of the library, what do I have to do to read these warnings and figure out what’s going wrong with my bulk load operation?

(Note: Please don’t suggest “solving” this by switching to the other MySql ADO.NET driver. For my use case, that would just be trading one problem for another, potentially worse one.)

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

There are two approaches:

SHOW WARNINGS

After MySqlBulkCopy.WriteToServer finishes, call ExecuteReader for a SHOW WARNINGS command. As per the documentation this will “[display] information about the conditions resulting from execution of the most recent nondiagnostic statement in the current session”.

InfoMessage event handler

Before executing MySqlBulkCopy.WriteToServer, attach an event handler to MySqlConnection.InfoMessage. During WriteToServer, the event handler will be called with an MySqlInfoMessageEventArgs object. This contains an Errors property that contains a list of errors and warnings that have occurred.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x