简体   繁体   English

C#MySQL命令超时

[英]C# MySQL command timeout

I have specified command_timeout for 4 seconds. 我已指定command_timeout 4秒钟。


But when I run the application, the command takes something about 8-12 seconds before it times out. 但是,当我运行该应用程序时,该命令花费了大约8-12秒的时间才能超时。


I also specified connection timeout in MySQL connection string, but with no luck 我还在MySQL连接字符串中指定了连接超时,但是没有运气

default command timeout=4 默认命令超时= 4

It works for MsSqll and Oracle well, but for MySQL not. 它适用于MsSqll和Oracle,但不适用于MySQL。

Is there any way how to specify the timeout? 有什么办法可以指定超时时间吗?

I found the issue there https://forums.mysql.com/read.php?38,634568,634568 but with no answer. 我在https://forums.mysql.com/read.php?38,634568,634568上找到了问题,但没有答案。

Edit 编辑

Code Sample 代码样例

...         
DataTable outputNodes = new DataTable();
Stopwatch sw = new Stopwatch();
cmd.CommandTimeout = 4;
sw.Start();
var a = cmd.ExecuteReader();
sw.Stop();
ex_time = sw.Elapsed;
sw.Reset();
outputNodes.Load(a);
CloseConnection();
...

This is probably a bug in Connector/NET. 这可能是Connector / NET中的错误。 I've run into a number of bugs with CommandTimeout , eg, bug 88124 , bug 87307 . 我遇到了CommandTimeout的许多错误,例如错误88124错误87307 I thought I even remembered filing a bug report about MySqlCommand taking 2× CommandTimeout before it actually timed out (which sounds like your situation), but I can't find it now (if I actually did file it). 我以为我甚至还记得在实际超时之前提交有关MySqlCommand占用2倍CommandTimeout的错误报告(这听起来像您的情况),但是现在找不到(如果我确实将其归档)。

If you have a consistent repro, I'd suggest filing a bug at bugs.mysql.com . 如果您的复制质量一致,建议您在bugs.mysql.com上提交错误。

And if you have the flexibility to change drivers, try MySqlConnector , which has a much more robust CommandTimeout implementation. 如果您可以灵活地更改驱动程序,请尝试MySqlConnector ,它具有更强大的CommandTimeout实现。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM