还原sqldatabase等待操作超时



我已经设置了使用Restore-Sqldatabase cmdlet恢复数据库的过程,并将其安排到SQL代理作业中。它一直工作正常,直到我尝试还原160GB数据库。基本上,它在600秒后失败,错误"等待操作时间超时"。我已经尝试添加0个语句时间,以查看它是否会解决此处,并更改SQL Server上的远程查询超时,但在10分钟后仍然倾斜。有人知道我是否可以更改另一个设置以增加超时?我正在运行的代码是:

# Load Module path! its not loading by default in calls from powershell
$env:PSModulePath=$env:PSModulePath + ";" + "C:Program FilesMicrosoft SQL Server110ToolsPowerShellModulesSQLPS"
## 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:SQLBACKUPDATABASE_RefreshTest_Latest.BAK" -ReplaceDatabase

出现的错误是:

Restore-SqlDatabase : The wait operation timed out
At H:SQLBACKUP_AutoScripts5_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参数:

指定在超时失败之前等待服务器连接的秒数。超时值必须是0到65534之间的整数。如果指定了0,则连接尝试不超时。

,您的命令可以成为:

Restore-SqlDatabase `
    -ServerInstance $server `
    -Database "Test" `
    -BackupFile "H:SQLBACKUPDATABASE_RefreshTest_Latest.BAK" `
    -ReplaceDatabase `
    -ConnectionTimeout 0

相关内容

  • 没有找到相关文章

最新更新