【发布时间】:2018-07-17 12:55:32
【问题描述】:
我已经设置了一个使用 Restore-SqlDatabase cmdlet 恢复数据库的过程,并将其安排到 SQl 代理作业中。在我尝试恢复 160GB 数据库之前,它一直运行良好。它基本上在 600 秒后失败,并出现错误“等待操作超时”。我尝试添加 0 的 StatementTimeout 以查看它是否会解决这个问题,并更改 SQL Server 上的远程查询超时,但它在 10 分钟后仍然出现。有谁知道我是否可以更改其他设置以增加超时?我正在运行的代码是:
# Load Module path! its not loading by default in calls from powershell
$env:PSModulePath=$env:PSModulePath + ";" + "C:\Program Files\Microsoft SQL Server\110\Tools\PowerShell\Modules\SQLPS\"
## Load module and run functions now
#Import SQL Server PowerShell Provider.
Import-Module "sqlps" -DisableNameChecking
#GEt Around Wait Timeout Error with Remote Connection via PoSh
$server = "THESERVER"
$serverConn = new-object ("Microsoft.SqlServer.Management.Smo.Server") $server
$serverConn.ConnectionContext.StatementTimeout = 0
#Restore Latest Copy of Test Database that was copied over
Restore-SqlDatabase -ServerInstance $server -Database "Test" -BackupFile "H:\SQLBACKUP\DATABASE_Refresh\Test_Latest.BAK" -ReplaceDatabase
出现的错误是:
Restore-SqlDatabase : The wait operation timed out
At H:\SQLBACKUP\_AutoScripts\5_Test_DBRESTORE.ps1:16 char:1
+ Restore-SqlDatabase -ServerInstance $server -Database "Test ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Restore-SqlDatabase], Win32Exception
+ FullyQualifiedErrorId : ExecutionFailed,Microsoft.SqlServer.Management.PowerShell.RestoreSqlDatabaseCommand
【问题讨论】:
-
尝试在Restore-SQLDatabase末尾添加:-ConnectionTimeout并定义值(以分钟为单位)
-
嗨弗拉基米尔。谢谢回复。不幸的是,添加 ConnectionTimeout 0 位后仍然会出现相同的错误。
-
尝试设置连接超时和执行超时
-
嗨 Sejal,我没有看到 Restore-SqlDatabase cmdlet 的执行超时选项。
标签: database powershell timeout wait sqlps