You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Software versions
MySqlConnector version:
Server type (MySQL, MariaDB, Aurora, etc.) and version:
.NET version:
(Optional) ORM NuGet packages and versions:
Describe the bug
A clear and concise description of what the bug is.
Exception
143 rows have been copied but 0 has been inserted
Code sample
` var connection = new MySqlConnection("[redacted]");
//creating object of MySqlBulkCopy
MySqlBulkCopy objbulk = new MySqlBulkCopy(connection);
//Mapping Table column
MySqlBulkCopyColumnMapping columnMapping;
foreach (var column in csvdt.Columns)
{
columnMapping = new MySqlBulkCopyColumnMapping(csvdt.Columns[column.ToString()].Ordinal, column.ToString());
objbulk.ColumnMappings.Add(columnMapping);
}
//inserting Datatable Records to DataBase
connection.Open();
MySqlConnector.MySqlBulkCopyResult result = objbulk.WriteToServer(csvdt);
//test.Load();
connection.Close();`
Expected behavior
I expected for it insert the rows
Additional context
It's a csv file that's being inserted into a MariaDB. This function is being called in a Foreach loop and inserts different csv files into different tables based on the file name. It inserts the first csv file and then fails on the remaining. I have forced it to skip the first file and start on the second and it still fails.
The text was updated successfully, but these errors were encountered:
Hmm, it may be the case that the errors aren't exposed if the Write method throws an exception; cf. #1012 (comment).
Please try this workaround:
varconnection=newMySqlConnection("[redacted]");connection.InfoMessage+=(s,e)=>{// use logging infrastructure of your choiceforeach(varerrorine.Errors)Console.WriteLine(error.Message);};// ...connection.Open();MySqlConnector.MySqlBulkCopyResultresult=objbulk.WriteToServer(csvdt);
Does the InfoMessage event handler provide enough information to diagnose the data issue causing no rows to be inserted?
Apparently it's violating a foreign key constraint. I'll share the output snippet below:
"Cannot add or update a child row: a foreign key constraint fails..."
So I should be able to make some adjustments from that. Thanks!
Software versions
MySqlConnector version:
Server type (MySQL, MariaDB, Aurora, etc.) and version:
.NET version:
(Optional) ORM NuGet packages and versions:
Describe the bug
A clear and concise description of what the bug is.
Exception
143 rows have been copied but 0 has been inserted
Code sample
` var connection = new MySqlConnection("[redacted]");
Expected behavior
I expected for it insert the rows
Additional context
It's a csv file that's being inserted into a MariaDB. This function is being called in a Foreach loop and inserts different csv files into different tables based on the file name. It inserts the first csv file and then fails on the remaining. I have forced it to skip the first file and start on the second and it still fails.
The text was updated successfully, but these errors were encountered: