SQL Server Powershell Upgrade Request

I am trying to connect to a Microsoft SQL database and update any record that the = field has changed to 'x'. I can query the database, but when I try to upgrade, I get this error.

Fill: An exception that throws a "Fill" with the argument "1": "Timed out." The timeout period before the operation is completed, or the server is not responding. "

#Create SQL Connection
$con = new-object "System.data.sqlclient.SQLconnection"

#Set Connection String
$con.ConnectionString =("Data Source=server;Initial Catalog=IDCards;Integrated Security=SSPI")
$con.open()

$sqlcmd = new-object "System.data.sqlclient.sqlcommand"
$sqlcmd.connection = $con
$sqlcmd.CommandTimeout = 600000
#$sqlcmd.CommandText = "select * from tblPhotoID where changed = 'X'"
$sqlcmd.CommandText = "UPDATE dbo.tblPhotoID SET Changed = '1' WHERE Changed ='X'"
$adapter = New-Object system.data.sqlclient.sqldataadapter ($sqlcmd.CommandText, $con)
$set = New-Object system.data.dataset
$adapter.Fill($set)

Currently updated about 4,000 entries. The script runs about 30 seconds before the timeout. I tried to increase the team timeout and got the same results.

+4
source share
2 answers

, . :

#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()
+17
$cn = New-Object System.Data.SqlClient.SqlConnection ( "Integrated Security=SSPI;Persist Security Info=False;Initial Catalog.......)
$q = "select ...  from .. "
$da = New-Object System.Data.SqlClient.SqlDataAdapter($q, $cn)
$da.SelectCommand.CommandTimeout = 60
-1

All Articles