vb.net SQL更新查询无法完成

时间:2016-05-16 19:48:00

标签: mysql sql vb.net

我正在尝试在vb.net应用程序中执行此更新查询:

SQL = "UPDATE billing_calldata SET status = 'c', customer = '" & customer_sequence & "', description = '" & description & "', customer_cost = '" & customer_cost & "', customer_ac = '" & customer_ac & "', customer_sc = '" & customer_sc & "', reseller_cost = '" & reseller_cost & "', reseller_ac = '" & reseller_ac & "', reseller_sc = '" & reseller_sc & "' WHERE sequence = '" & sequence & "';"

但它花了很多年,甚至没有完成。

ExecuteNonQuery()上说:

Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.

是什么导致它无法完成?

我已经复制了查询(使用正确的值),并尝试直接在服务器上运行,大约需要49秒(但实际上已完成)

我在表格

中的sequence列添加了索引

1 个答案:

答案 0 :(得分:3)

您可以尝试将CommandTimeout设置为更高的值。对于Sql Server,默认值是30秒,我没有MySql的参考,但它可能是相同的。因此,如果您在服务器上执行的命令需要49秒,那么代码中的超时30秒肯定是一个showstopper。

 command.CommandTimeout = 60

但是,请允许我提醒您查询中存在更大问题。使用Sql Injection方案可以轻松攻击此查询。最好尽快搜索参数化查询并改变编码习惯。

编辑对于Sql Server,MySqlCommand的超时时间为30秒。
Found a reference here