命令执行期间遇到MySQL致命错误 - 循环通过文件夹中的所有csv文件以加载数据本地infile [英] MySQL fatal error encountered during command execution - looping through all csv files in folder for load data local infile
本文介绍了命令执行期间遇到MySQL致命错误 - 循环通过文件夹中的所有csv文件以加载数据本地infile的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
MySQL命令在MySQL本身工作正常,但是当我在我的c#程序,它说发生错误0:命令执行期间遇到致命错误。
The MySQL command works fine in MySQL itself but when I do it over my c# program, it says "Error 0 has occurred: Fatal error encountered during command execution.".
有什么我做错了在这里与我的c#代码?我的代码循环通过文件夹中的所有csv文件,然后导入csv数据到MySQL数据库。非常感谢任何建议。
Is there anything I did wrongly here with my c# code? My code loops through all the csv files in the folder, then import csv data into MySQL database. Any advice would be much appreciated!
private void btn_importCSV_Click(object sender, EventArgs e)
{
var CSVfolder = Directory.EnumerateFiles(sourceDirCSV);
foreach (string CSVfile in CSVfolder)
{
try
{
using (var connection = new MySqlConnection(strProvider))
using (var command = connection.CreateCommand())
{
connection.Open();
command.CommandTimeout = 5000000;
command.CommandText = @"load data local infile 'C:\\Full\\Path\\To\\" + CSVfile + "' into table prices fields terminated by ',' lines terminated by '\n' (@date, Prices_Time, Prices_Open, Prices_High, Prices_Low, Prices_Close, Prices_Volume, Tickers_Ticker_ID) set Prices_Date = str_to_date(@date, '%e/%c/%Y');";
command.ExecuteNonQuery();
connection.Close();
}
}
catch (MySqlException ex)
{
MessageBox.Show("Error " + ex.Number + " has occurred: " + ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
DialogResult dialogResult = MessageBox.Show("Done importing into MySQL database! Do you want to view the data via DataGrid table?", "View Table in DataGrid", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
FillGrid_FetchSharePrices();
}
else if (dialogResult == DialogResult.No)
{
//Do nothing
}
}
推荐答案
检查您的连接字符串是否包含以下内容:
Check that your connection string includes the following:
允许用户变量= True;
"Allow User Variables=True;"
这解决了我的问题。
这篇关于命令执行期间遇到MySQL致命错误 - 循环通过文件夹中的所有csv文件以加载数据本地infile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文