Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从Azure WebJob连接到MySQL时出现随机问题_C#_Mysql_.net_Azure_Azure Webjobs - Fatal编程技术网

C# 从Azure WebJob连接到MySQL时出现随机问题

C# 从Azure WebJob连接到MySQL时出现随机问题,c#,mysql,.net,azure,azure-webjobs,C#,Mysql,.net,Azure,Azure Webjobs,我有一个连接MySQL数据库的应用程序。当应用程序在Windows Server 2016上运行时,一切正常,但最后我将其作为连续Web作业迁移到Azure应用程序服务,我收到了完全随机的错误: MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. ---> MySql.Data.MySqlClient.MySqlExceptio

我有一个连接MySQL数据库的应用程序。当应用程序在Windows Server 2016上运行时,一切正常,但最后我将其作为连续Web作业迁移到Azure应用程序服务,我收到了完全随机的错误:

MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts. ---> 
MySql.Data.MySqlClient.MySqlException (0x80004005): Timeout expired.  
The timeout period elapsed prior to completion of the operation or the server is not responding.
   at MySql.Data.Common.StreamCreator.GetTcpStream(MySqlConnectionStringBuilder settings)
   at MySql.Data.Common.StreamCreator.GetStream(MySqlConnectionStringBuilder settings)
   at MySql.Data.MySqlClient.NativeDriver.Open()
   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 System.Data.Common.DbConnection.OpenAsync(CancellationToken cancellationToken)
--- 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 Dapper.SqlMapper.<ExecuteImplAsync>d__39.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()``
MySQL版本是5.5-相当旧,但它是客户的外部源代码,我对此无能为力。 我为.NET测试了三个版本的MySQL驱动程序(8.0、6.9、6.10)——每个版本都会出错

我在某处发现了一些信息,这种情况可能是由于太多打开的套接字造成的,但我用
netstat
命令在本地测试了这个应用程序,一切看起来都很好

我的问题与此类似: 但是没有任何有用的答案


我从来没有用过MySQL,所以我不是这个工具的专家。可能有人有类似的情况???

尝试在托管管理面板中将您的IP添加到白名单中我将Azure Web App中的每个出站IP地址添加到MySQL中的白名单中。我在Wireshark中调查了Azure中的日志,发现在出现错误的情况下,创建新的TCP连接存在问题。看起来我的请求有时无法从Azure中发出(???)尝试删除连接字符串中的“端口”我在连接字符串中没有端口:
Server=123.123.123;数据库=xxxxx;Uid=xxxxx;Pwd=xxxxxx;转换为零日期时间=真;maximumpoolsize=20;连接超时=10此线程中的某个修复程序可能会有所帮助。尝试将您的IP添加到托管管理面板中的白名单我将Azure Web App中的每个出站IP地址添加到MySQL中的白名单中。我在Wireshark中调查了Azure中的日志,发现在出现错误的情况下,创建新的TCP连接存在问题。看起来我的请求有时无法从Azure中发出(???)尝试删除连接字符串中的“端口”我在连接字符串中没有端口:
Server=123.123.123;数据库=xxxxx;Uid=xxxxx;Pwd=xxxxxx;转换为零日期时间=真;maximumpoolsize=20;连接超时=10此线程中的某个修复程序可能会有所帮助。
using (IDbConnection connection = new MySqlConnection(connectionString))
{
    return await connection.QueryAsync<Resource>(this._getContactsToSync);
}