我構建的應用程序備份我的MySQL數據庫的服務器,一天一天,數據庫變得比以前大了,這引起一些次錯誤(從我的角度來看):超時時間已在MySQL備份 - C#
消息:超時過期。操作完成之前超時的時間或服務器沒有響應。 完整:MySql.Data.MySqlClient.MySqlException(0x80004005):超時過期。操作完成之前超時的時間或服務器沒有響應。 ---> System.TimeoutException:在IO操作中超時 at MySql.Data.MySqlClient.TimedStream.StopTimer() at MySql.Data.MySqlClient.TimedStream.Read(Byte [] buffer,Int32 offset,Int32 count) at System.IO.BufferedStream.Read(Byte [] array,Int32 offset,Int32 count) at MySql.Data.MySqlClient.MySqlStream.ReadFully(Stream stream,Byte [] buffer,Int32 offset,Int32 count) at MySql.Data .MySqlClient.MySqlStream.LoadPacket() 在MySql.Data.MySqlClient.MySqlStream.ReadPacket() 在MySql.Data.MySqlClient.NativeDriver.FetchDataRow(的Int32 statementId,的Int32列) 在MySql.Data.MySqlClient.Driver.FetchDataRow (的Int32 statementId,的Int32列) 在MySql.Data.MySqlClient.ResultSet.GetNextRow() 在MySql.Data.MySqlClient.ResultSet.NextRow(的CommandBehavior行爲) 在MySql.Data.MySqlClient.MySqlDataReader.Read() 在MySql.Data.MySqlClient.ExceptionInterceptor.Throw(例外的例外) 在MySql.Data.MySqlClient .MySqlConnection.Throw(異常前) 在MySql.Data.MySqlClient.MySqlConnection.HandleTimeoutOrThreadAbort(異常前) 在MySql.Data.MySqlClient.MySqlDataReader.Read() 在MySql.Data.MySqlClient.MySqlBackup.Export_RowsData(字符串表名,字符串selectSQL) 在MySql.Data.MySqlClient.MySqlBackup.Export_Rows(字符串表名,字符串selectSQL) 在MySql.Data.MySqlClient.MySqlBackup.Export_TableRows() 在MySql.Data.MySqlClient.MySqlBackup.ExportStart() 在MySql.Data.MySqlClient.MySqlBackup.ExportToFile(字符串文件路徑) 在MYSQL_Auto_Backup.Form1.Backup()在C:\用戶\貝拉爾\文件\的Visual Studio 2012 \項目\ MYSQL自動備份\ MYSQL自動備份\ Form1中。 CS:行132
代碼:
// Backup...
DateTime Time = DateTime.Now;
year = Time.Year;
month = Time.Month;
day = Time.Day;
hour = Time.Hour;
minute = Time.Minute;
second = Time.Second;
millisecond = Time.Millisecond;
//Save file to Path with the current date as a filename
string path;
path = txb_Path.Text + year + "-" + month + "-" + day + "--" + hour + "-" + minute + "-" + second + ".sql";
file = path;
using (MySqlConnection conn = new MySqlConnection(connectionString))
{
using (MySqlCommand cmd = new MySqlCommand())
{
using (MySqlBackup mb = new MySqlBackup(cmd))
{
cmd.Connection = conn;
conn.Open();
mb.ExportToFile(file);
conn.Close();
}
}
}
我做到了通過添加:mb.Command.CommandTimeout = int.MaxValue; –