Dan*_*nch 5 sql-server powershell
我正在尝试连接到Microsoft SQL数据库并将更改的字段=的任何记录更新为"x".我能够查询数据库但是当我尝试进行更新时,我收到此错误
Fill:使用"1"参数调用"Fill"的异常:"Timeout expired.在操作完成之前经过了超时时间,或者服务器没有响应."
Fill : Exception calling "Fill" with "1" argument(s): "Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding."
目前有大约4000条记录会更新.该脚本在超时前运行约30秒.我已经尝试增加命令超时并获得相同的结果.
小智 21
您的更新语句不会返回记录集,因此没有任何内容可以填充数据集.你想尝试以下方法:
#Create SQL Connection
$con = new-object "System.data.sqlclient.SQLconnection"
#Set Connection String
$con.ConnectionString =(“Data Source=sb-inft-orange.ads.iu.edu;Initial Catalog=IDCards;Integrated Security=SSPI”)
$con.open()
$sqlcmd = new-object "System.data.sqlclient.sqlcommand"
$sqlcmd.connection = $con
$sqlcmd.CommandTimeout = 600000
$sqlcmd.CommandText = “UPDATE dbo.tblPhotoID SET Changed = '1' WHERE Changed ='X'”
$rowsAffected = $sqlcmd.ExecuteNonQuery()
| 归档时间: | 
 | 
| 查看次数: | 35546 次 | 
| 最近记录: |