Mac*_*cko 4 mysql .net-core-2.0 pomelo-entityframeworkcore-mysql
我们在生产环境中使用 Pomelo MySql 半年了,它运行得很好,但偶尔我们会遇到如下异常:
MySql.Data.MySqlClient.MySqlException: The Command Timeout expired before the operation completed.
Run Code Online (Sandbox Code Playgroud)
appsettings.json 中的连接字符串如下所示:
"MySqlConnection": "服务器=somesql;用户id=用户;密码=pass;数据库=测试;"
所以没什么特别的。
我的问题是 pomelo 中默认的命令执行超时是多少?如何通过连接字符串更改它?
在 DbContext 中执行这样的代码
var timeout = Database.GetCommandTimeout();
Run Code Online (Sandbox Code Playgroud)
总是给我空值。
小智 7
尝试通过指定 来增加连接字符串中的命令超时(以秒为单位) default command timeout。
在您的情况下,您的连接字符串应如下所示:
server=somesql;userid=user;password=pass;database=test;default command timeout=120;
Run Code Online (Sandbox Code Playgroud)