ADO.NET Driver for MySQL
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
在業務邏輯及數據不變的情況下,僅更換
MySql.Data.dll就出現異常讓我費盡了心思。
其實在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"); }

}
只讀屬性,默認值為15秒,可以在連接字符串設置。
在
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(); }

}
默認值是0,表示沒時長限制?猜的。對其賦值如不為0,則拋出異常,也就是說賦值只能為0,那也就是該屬性只讀了?其值不可改變。
再來看新版本的,在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;

}

}
屬性可讀寫,默認值為15秒。
在
command.cs類中有

[Category("Misc")]

[Description("Time to wait for command to execute")]

[DefaultValue(30)]

public override int CommandTimeout


{


get

{ return commandTimeout; }


set

{ commandTimeout = value; }

}
屬性可讀寫,默認值為30秒(這些默認值感覺跟SQLServer一樣的),這一點跟1.0.7就不同了。1.0.7為只讀且值為0。
我感覺前面提到的Timeout異常跟這裡有很大關系,准備測試下.......