我试图加载大数据文件,例如10 MB文件到数据库使用加载数据本地INFILE到MySQL使用Windows服务。但是它失败了,windows服务没有任何异常就停止了。我尝试使用2 MB等小尺寸文件,并成功完成。无法使用加载数据infile本地到mysql加载大文件
有没有什么办法可以将大文件加载到mysql数据库中?而Windows服务停止的原因可能是什么?
这里是我的代码..
public int UpdateDataBase(string query, string filename, Logger swLog)
{
int status = 0;
using (MySqlConnection myconnection = new MySqlConnection(connectionCdrBank))
{
try
{
myconnection.ConnectionTimeout = 1000;
myconnection.Open();
myconnection.BeginTransaction();
MySqlCommand mycommand = new MySqlCommand("ClearTempTable", myconnection);
mycommand.CommandType = CommandType.StoredProcedure;
status = mycommand.ExecuteNonQuery();
MySqlCommand mycommand1 = new MySqlCommand(query, myconnection);
mycommand1.CommandTimeout = 1000;
status = mycommand1.ExecuteNonQuery();
MySqlCommand mycommand2 = new MySqlCommand("InsertToCdrDetailsTempTable", myconnection);
mycommand2.CommandType = CommandType.StoredProcedure;
mycommand2.CommandTimeout = 1000;
status = Convert.ToInt32(mycommand2.ExecuteScalar());
myconnection.Commit();
myconnection.Close();
}
catch (Exception ex)
{
Console.WriteLine("Error:" + ex.Message);
if (myconnection.State == ConnectionState.Open)
myconnection.Rollback();
status = (ex.Message.IndexOf("Duplicate entry") != -1) ? -1000 : 0;
swLog.WriteErrorToLog("");
swLog.WriteErrorToLog("Error while saving: " + ex.Message);
mail.SentMail("Error while saving:", ex.Message);
swLog.CloseLogger();
}
}
return status;
}
哪里查询
LOAD DATA LOCAL INFILE 'a.txt' INTO TABLE tbl_cdrload" FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
错误日志中是否有相关条目? 10MB不是一个巨大的文件加载。我定期从很多GB文件加载数据。 – nnichols 2012-02-10 17:44:56
什么都没有记录......实际上,当我试图调试service.It它不会抛出异常,它只是停止Windows服务。 – Jay 2012-02-10 17:55:49