我試圖加載大數據文件,例如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