我正在使用MySQL Connector/Net 6.7.4在Windows 8商店應用程序中向MySQL數據庫發送和接收數據。它完美地適用於一臺機器,但不適用於另一臺機器。無法在一臺機器上連接到MySQL數據庫
以下是錯誤:
A first chance exception of type 'System.AggregateException' occurred in mscorlib.dll A first chance exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.RT.DLL A first chance exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.RT.DLL A first chance exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.RT.DLL MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the specified MySQL hosts. ---> System.AggregateException: One or more errors occurred. ---> System.Threading.Tasks.TaskCanceledException: A task was canceled. --- End of inner exception stack trace --- at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions) at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken) at System.Threading.Tasks.Task.Wait() at MySql.Data.Common.MyNetworkStream.OpenConnection() at MySql.Data.Common.MyNetworkStream.Open() at MySql.Data.Common.MyNetworkStream.CreateStream(MySqlConnectionStringBuilder settings, Boolean unix) at MySql.Data.Common.StreamCreator.GetTcpStream(MySqlConnectionStringBuilder settings) at MySql.Data.Common.StreamCreator.GetStream(MySqlConnectionStringBuilder settings) at MySql.Data.MySqlClient.NativeDriver.Open() --- End of inner exception stack trace --- at MySql.Data.MySqlClient.NativeDriver.Open() at MySql.Data.MySqlClient.Driver.Open() at MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder settings) at MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() at MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() at MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() at MySql.Data.MySqlClient.MySqlPool.GetConnection() at MySql.Data.MySqlClient.MySqlConnection.Open() at QuantiView.Classes.clsGlobal.mMySqlConnect() A first chance exception of type 'System.InvalidOperationException' occurred in MySql.Data.RT.DLL A first chance exception of type 'System.InvalidOperationException' occurred in mscorlib.dll System.InvalidOperationException: Connection must be valid and open. at MySql.Data.MySqlClient.MySqlConnection.Throw(Exception ex) at MySql.Data.MySqlClient.MySqlCommand.Throw(Exception ex) at MySql.Data.MySqlClient.MySqlCommand.CheckState() at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader() at QuantiView.Classes.clsGlobal.d_20.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult() at QuantiView.Pages.p1Project.d_f.MoveNext()
和連接代碼:
public static void mMySqlConnect()
{
Debug.WriteLine("mMySqlConnect");
Debug.WriteLine("internet = " + IsInternet());
if (connection.Equals(null)) connection = new MySqlConnection(connectionString);
try
{
if (connection.State.Equals(ConnectionState.Closed)) connection.Open();
}
catch (MySqlException ex)
{
Debug.WriteLine(ex.ToString());
switch (ex.Number)
{
case 0:
Debug.WriteLine("Cannot connect to server. Contact administrator");
break;
case 1045:
Debug.WriteLine("Invalid username/password, please try again");
break;
}
}
}
兩臺機器都運行Win8.1全面更新,同一版本的VS(2013還更新) ,具有相同的引用和安裝的程序集,都連接到同一個網絡。
檢查此[鏈接](http://bugs.mysql.com/bug.php? ID = 69760)。 – Brian
你檢查過兩臺機器的防火牆設置嗎?兩臺機器上的防火牆設置是否相同? – Navid
該解決方法的鏈接對Brian很有幫助,但它是針對winforms,WPF,web應用程序編寫的,因爲它建議更改web.config,app.config或machine.config ...其中沒有一個用於Windows 8商店應用。 – Gary95054