在powershell中扩展事务作用域超时
我正在运行PowerShell脚本来升级我的数据库。我已经实现了transactionscope以在脚本错误时回滚更改。在某些数据库上完成升级脚本需要很长时间。在这种长时间运行的情况下,事务作用域在10分钟后放弃,尽管我已经设置了一个很长的超时时间。下面是我实现的代码片段在powershell中扩展事务作用域超时,powershell,Powershell,我正在运行PowerShell脚本来升级我的数据库。我已经实现了transactionscope以在脚本错误时回滚更改。在某些数据库上完成升级脚本需要很长时间。在这种长时间运行的情况下,事务作用域在10分钟后放弃,尽管我已经设置了一个很长的超时时间。下面是我实现的代码片段 $timeout = New-Object System.TimeSpan -ArgumentList @(24,0,0) # 24 hours $options = [System.Transactions.Tran
$timeout = New-Object System.TimeSpan -ArgumentList @(24,0,0) # 24 hours
$options = [System.Transactions.TransactionScopeOption]::Required
$scope = New-Object -TypeName System.Transactions.TransactionScope -ArgumentList @($options,$timeout)
Try{
Write-Output "SQL Transaction initiated"
$SqlFiles | Foreach-Object {
$sqlFile = $_
Write-Output "$((get-date).ToString('T')) - Processing file: $sqlFile"
Invoke-Sqlcmd -ErrorAction 'Stop' -ServerInstance $ServerInstance -Database $Database -Username $Username -Password $Password -InputFile $sqlFile -Variable $SQLParameters
Write-Output "$((get-date).ToString('T')) - Completed file: $sqlFile"
}
$scope.Complete()
}
catch{
Write-Output "$((get-date).ToString('T')) - SQL error occured rolling back transaction"
throw $_.exception
}
finally{
$scope.Dispose()
}
我可以知道如何增加事务作用域超时吗?我尝试在machine.config中更新事务范围,但没有帮助
多谢各位