我构建的应用程序备份我的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; –