MySql.Data.dll是.Net访问MySQL数据库的一个驱动,完全ADO.NET数据访问模式,由MySQL官方提供,有多个版本可选择。
最早使用的环境:.Net2.0+MySQL5.x+MySQL.data.dll 1.0.7,感觉似乎很稳定,一直没什么大问题。随着系统升级,尝试更新MySql.Data.dll版本(1.07版本官方早不提供下载了,现在最新版本分别是:1.0.10,5.0.8,5.1.4),问题出现了,经常会出现异常
The timeout period elapsed prior to completion of the operation or the server is not responding其实在SQLServer中有时也出现此问题,有人建议设置ConnectionTimeout和CommandTimeout时长来解决,MySql.Data.dll中也有这些属性,下载了MySql.Data.dll的源码,看了下,似乎发现了一线希望,在1.07版本的源码中ConnectionString.cs类中有
[Category("Connection")]
[Description("Number of seconds to wait for the connection to succeed")]
[DefaultValue(15)]
public int ConnectionTimeout
{
get { return GetInt("connect timeout"); }
}在command.cs类中有
[Category("Misc")]
[Description("Time to wait for command to execute")]
public int CommandTimeout
{
// TODO: support this
get { return 0; }
set { if (value != 0) throw new NotSupportedException(); }
}再来看新版本的,在5.0.8的源码中MySqlConnectionStringBuilder.cs类中有
[Category("Connection")]
[DisplayName("Connect Timeout")]
[Description("The length of time (in seconds) to wait for a connection " +
"to the server before terminating the attempt and generating an error.")]
[DefaultValue(15)]
[RefreshProperties(RefreshProperties.All)]
public uint ConnectionTimeout
{
get { return connectionTimeout; }
set
{
SetValue("Connect Timeout", value);
connectionTimeout = value;
}
}在command.cs类中有
[Category("Misc")]
[Description("Time to wait for command to execute")]
[DefaultValue(30)]
public override int CommandTimeout
{
get { return commandTimeout; }
set { commandTimeout = value; }
}我感觉前面提到的Timeout异常跟这里有很大关系,准备测试下.......
PS:希望能在园子里找些用MySQL的朋友,有问题可以一起探讨,在社区建了个小组: .Net+MySQL
