JustScriptIt
Technical User
Hello,
I am scripting in powershell to read from table, and then update table.
It works very well - except when another user or program is trying to read or update the table at the same time.
This is unavoidable, so I would like to know how to prevent transaction deadlocks.
Here is code to read from the large table
Here is code to update the large table:
I am scripting in powershell to read from table, and then update table.
It works very well - except when another user or program is trying to read or update the table at the same time.
This is unavoidable, so I would like to know how to prevent transaction deadlocks.
Here is code to read from the large table
Code:
$conn.Open()
$sql = SQL statement to read table
$cmd = New-Object System.Data.SqlClient.SqlCommand($sql,$conn)
$rdr = $cmd.ExecuteReader()
while ($rdr.read()){
$sql_output += ,@($rdr.GetValue(0), $rdr.GetValue(1), $rdr.GetValue(2), $rdr.GetValue(3))
}
$conn.Close()
Here is code to update the large table:
Code:
$conn_update.Open()
$sql_update = SQL statement to update table
$cmd_update = New-Object System.Data.SqlClient.SqlCommand($sql_update,$conn_update)
$found = $cmd_update.ExecuteNonQuery()
$conn_update.Close()