简体   繁体   中英

SQL Server on Azure: "Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding."

I'm running a script locally in Powershell that loops bcp, copying hundreds of excel files to a database on Azure (I simply entered the.network information as arguments to bcp). On each execution of the loop, I also make a query that updates a column of the table. At the beginning, it works fine. But about a minute in, it slows to a halt and finally produces this error.

47680 rows copied.
Network packet size (bytes): 4096
Clock Time (ms.) Total     : 18250  Average : (2612.60 rows per sec.)
Exception calling "ExecuteReader" with "0" argument(s): "Execution Timeout 
Expired.  The timeout period elapsed prior to completion of the operation or the server is not responding."

I'm not sure what's going on here. Here's the query it's timing out on:

$query = "UPDATE $tableName SET jobID = $dir_id where jobID is NULL;"
$sqlCmd3 = $connection.CreateCommand()
$sqlCmd3.Connection = $connection
$sqlCmd3.CommandText = $query
$sqlCmd3.ExecuteReader() *>$null

Have you tried to use " ExecuteNonQuery " instead of your " ExecuteReader "? Execute reader opens a stream to read from which you should close by calling " EndExecuteReader ". Also, you use update statement which is NonQuery statement - just use ExecuteNonQuery instead.

The comment from Jakob is the correct answer. It is not enough to set timeout on your sql server connection as the sql command it self also has a timeout. Increase both if you have timeout issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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