我使用Visual Studio 2008和C#來訪問MySql數據庫。到目前爲止,我依靠Visual Studio來爲DataSet創建代碼,這似乎給我一個問題。如果數據庫不可訪問(即未運行),則會顯示「MySqlException未處理」,「無法連接到任何指定的MySQL主機」。如何處理DataSet.Designer.cs中的異常?
我的問題是什麼是處理這種異常的最佳方法?
我希望能夠在不篡改designer.cs文件的情況下處理它,但如果這不可能,那麼解決此問題的任何方法都可以。
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.ComponentModel.Design.HelpKeywordAttribute("vs.data.TableAdapter")]
[global::System.ComponentModel.DataObjectMethodAttribute(global::System.ComponentModel.DataObjectMethodType.Fill, true)]
public virtual int Fill(customerDataSet.addressesDataTable dataTable) {
this.Adapter.SelectCommand = this.CommandCollection[0];
if ((this.ClearBeforeFill == true)) {
dataTable.Clear();
}
// Exception occurs on the line below.
int returnValue = this.Adapter.Fill(dataTable);
return returnValue;
}
你什麼時候得到這個異常?在視覺工作室設計師?在你的代碼?如果您在代碼中遇到異常情況,可否請您發佈相關部分? – 2009-09-17 08:52:29
異常不會發生在文件中。什麼是方法? – 2009-09-17 10:07:42