【发布时间】:2016-04-18 18:43:11
【问题描述】:
如果 max_user_connections 连接已经打开,有没有办法告诉 Entity Framework 等待?
我想我可以捕捉到异常并重试或保留一个计数器,但这充其量只是感觉很老套。
我的 Azure 日志充满了以下消息:
System.Data.Entity.Core.EntityException: The underlying provider failed on Open.
MySql.Data.MySqlClient.MySqlException:
Authentication to host 'xxx' for user 'yyy' using method 'mysql_native_password' failed with message:
User 'yyy' has exceeded the 'max_user_connections' resource (current value: 4)
我尝试将Max Pool Size=4 添加到连接字符串,但没有帮助。
<add name="DbContext" connectionString="Database=db;Data Source=xxx;User Id=yyy;Password=zzz;CharSet=utf8;Persist Security Info=True;Convert Zero Datetime=True;Max Pool Size=4" providerName="MySql.Data.MySqlClient" />
【问题讨论】:
-
max_user_connections是一个数据库参数,所以 EF 在登录之前无法知道它。我相信你能做的最好的就是捕获异常并处理它。 -
我知道每个环境的
max_user_connections。有什么办法可以告诉 EF 不要打开更多连接? -
您可以将其作为参数管理并在上下文构造函数中进行处理,但在应用程序的所有实例之间同步此值会非常麻烦。我相信最好的方法是抓住那个例外。
标签: c# mysql entity-framework azure asp.net-web-api2