I'm using MySQL LOAD DATA INFILE Data
command to bulk insert data to a table. Here's how I am doing it :
LOAD DATA INFILE 'MyFile.csv' INTO TABLE `dbname`.`tablename` FIELDS TERMINATED BY '\t' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' ;
When I run it from our C# project I'm getting a Data too long for column xxx
exception for a char(50) column which the provided data for it is less than 50 (but it is in Persian)but when I use a MySql client such as SQLyog it is working fine.
Here's how I am running this command :
private static void RunCommand(string command,params object[] args)
{
if (args != null)
command = string.Format(command, args);
using (var conn = MySqlClientFactory.Instance.CreateConnection())
{
if (conn == null) return;
conn.ConnectionString =
"Server=localhost;Uid=root;Pwd=123456; AutoEnlist=false;Charset=utf8;";
conn.Open();
using (var comm = conn.CreateCommand())
{
comm.CommandText = command;
comm.ExecuteNonQuery();
}
}
}
I guess that it could be an issue of converting Unicode
characters but I can not figure out how can I make it run correctly.