无法使用部署在 Aws Ecs 上的 .net 核心应用程序连接到 Aurora MySql
Unable to connect to Aurora MySql using .net core application deployed on Aws Ecs
我在 .net core 3.1 中有一个应用程序,我正在使用 MySql。要连接到 MySql,我正在使用 Pomelo.EntityFrameworkCore.MySql nuget。
我的 .net 核心应用程序作为 docker 容器部署在 AWS ECS 上,我正在使用 Aurora MySql RDS 来存储数据。我已经授予 "Publicly accessible" 访问 Aurora MySql 的权限,我可以使用 MySql workbench 连接到数据库,也可以使用本地主机连接到我的 .net 核心应用程序。但是当我部署应用程序并尝试执行任何数据库操作时,它开始抛出异常:
An exception has been raised that is likely due to a transient
failure. Consider enabling transient error resiliency by adding
'EnableRetryOnFailure()' to the 'UseMySql' call.
然后我添加了这样的重试模式:
services.AddDbContextPool<DataContext>(options =>
options.UseMySql(Configuration.GetConnectionString("DefaultConnection"), builder =>
{
builder.EnableRetryOnFailure(5, TimeSpan.FromSeconds(5), null);
}
);
我的连接字符串是这样的:
"DefaultConnection": "Server=db-cluster-1-instance-1.cqb2fsjwx78p.us-east-2.rds.amazonaws.com;Database=dbName;User ID=admin;Password=password;port=3306"
添加重试模式后。我收到此错误:
"Maximum number of retries (5) exceeded while executing database
operations with 'MySqlRetryingExecutionStrategy'. See inner exception
for the most recent failure."
所以我怀疑是另外一回事。我在这里做错了什么?或者它可能是 aws 方面的问题
将 SslMode=None
添加到您的连接字符串并查看连接是否有效(请参阅 MySqlConnector's Connection String Options)。暂时性异常只是意味着 Pomelo(即 MySqlConnector)无法连接到数据库服务器。
所以这与连接问题有关(可以通过更改连接字符串或更改 Aurora/firewall 配置来解决)。
所以这个问题与我提取的 docker 图片有关。
我正在使用 mcr.microsoft.com/dotnet/core/sdk:3.1
。将其更改为 mcr.microsoft.com/dotnet/core/sdk:3.1-bionic
有效。
https://github.com/dotnet/SqlClient/issues/222
我在 .net core 3.1 中有一个应用程序,我正在使用 MySql。要连接到 MySql,我正在使用 Pomelo.EntityFrameworkCore.MySql nuget。
我的 .net 核心应用程序作为 docker 容器部署在 AWS ECS 上,我正在使用 Aurora MySql RDS 来存储数据。我已经授予 "Publicly accessible" 访问 Aurora MySql 的权限,我可以使用 MySql workbench 连接到数据库,也可以使用本地主机连接到我的 .net 核心应用程序。但是当我部署应用程序并尝试执行任何数据库操作时,它开始抛出异常:
An exception has been raised that is likely due to a transient failure. Consider enabling transient error resiliency by adding 'EnableRetryOnFailure()' to the 'UseMySql' call.
然后我添加了这样的重试模式:
services.AddDbContextPool<DataContext>(options =>
options.UseMySql(Configuration.GetConnectionString("DefaultConnection"), builder =>
{
builder.EnableRetryOnFailure(5, TimeSpan.FromSeconds(5), null);
}
);
我的连接字符串是这样的:
"DefaultConnection": "Server=db-cluster-1-instance-1.cqb2fsjwx78p.us-east-2.rds.amazonaws.com;Database=dbName;User ID=admin;Password=password;port=3306"
添加重试模式后。我收到此错误:
"Maximum number of retries (5) exceeded while executing database operations with 'MySqlRetryingExecutionStrategy'. See inner exception for the most recent failure."
所以我怀疑是另外一回事。我在这里做错了什么?或者它可能是 aws 方面的问题
将 SslMode=None
添加到您的连接字符串并查看连接是否有效(请参阅 MySqlConnector's Connection String Options)。暂时性异常只是意味着 Pomelo(即 MySqlConnector)无法连接到数据库服务器。
所以这与连接问题有关(可以通过更改连接字符串或更改 Aurora/firewall 配置来解决)。
所以这个问题与我提取的 docker 图片有关。
我正在使用 mcr.microsoft.com/dotnet/core/sdk:3.1
。将其更改为 mcr.microsoft.com/dotnet/core/sdk:3.1-bionic
有效。
https://github.com/dotnet/SqlClient/issues/222