gpt4 book ai didi

c# - 无法仅在一台机器上连接到 MySQL 数据库

转载 作者:行者123 更新时间:2023-11-30 00:54:34 25 4
gpt4 key购买 nike

我正在使用MySQL Connector/Net 6.7.4在 Windows 8 应用商店应用程序中向 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也更新),具有相同的引用和安装的程序集,连接到相同的网络。

最佳答案

打开Package.appxmanifest打开功能选项卡并检查专用网络(客户端和服务器)

关于c# - 无法仅在一台机器上连接到 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20693814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com