2016-05-16 52 views
-2

我試圖在vb.net應用程序來執行此更新查詢:vb.net SQL更新查詢無法完成

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

您是否知道,如果客戶說'Ziggy's Hardware',那麼以這種方式創建SQL會崩潰?而且它強制這些成本項目串?使用SQL參數 – Plutonix

+1

你對換行符有什麼作用? –

+0

@Plutonix客戶列只有一個整數,所以永遠不會有任何''' – charlie

回答

3

您可以嘗試將CommandTimeout設置爲更高的值。 Sql Server的默認值是30秒,我沒有MySql的參考,但它可以相等。所以,如果你的命令在服務器上執行需要49秒,那麼從你的代碼中超時30秒,它肯定是一個炫耀者。

command.CommandTimeout = 60 

但是,讓我警告你一個更大的問題在你的查詢。這個查詢可能很容易用Sql Injection方案攻擊。最好儘快搜索參數化查詢並更改編碼習慣。

編輯對於Sql Server,MySqlCommand的超時時間爲30秒。
Found a reference here

+0

如果您在使用時查看'MySqlConnectionStringBuilder.ConnectionTimeout',默認值爲15 – Plutonix

+0

Uhm,但那是ConnectionTimeout而不是CommandTimeout – Steve

+0

Ack!對不起,我感到困惑。 – Plutonix