简体   繁体   English

Restore-SqlDatabase等待操作超时

[英]Restore-SqlDatabase Wait operation timeout

I have setup a process for Restoring Databases using the Restore-SqlDatabase cmdlet and scheduled this into a SQl Agent job. 我已经设置了使用Restore-SqlDatabase cmdlet还原数据库的过程,并将其调度到SQl Agent作业中。 It's been working fine until I tried to restore a 160GB database. 在尝试还原160GB数据库之前,它一直运行良好。 It basically fails after 600s with the error "The wait operation timed out". 它基本上在600秒后失败,并显示错误“等待操作超时”。 I've tried adding in a StatementTimeout of 0 to see if it would get round this and also change the Remote query Timeout on the SQL Server but it still bobmbs out after 10 minutes. 我尝试添加一个StatementTimeout为0来查看它是否可以解决这个问题,并且还更改了SQL Server上的远程查询超时,但是它在10分钟后仍然突然消失。 Does anyone know if there is another setting I can change to increase the timeout? 有人知道我是否可以更改其他设置以增加超时时间? The Code I'm running is: 我正在运行的代码是:

# 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

Error That Appears is: 出现的错误是:

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

It looks like Restore-SqlDatabase has a -ConnectionTimeout parameter: 它看起来像Restore-SqlDatabase-ConnectionTimeout参数:

Specifies the number of seconds to wait for a server connection before a timeout failure. 指定超时失败之前等待服务器连接的秒数。 The timeout value must be an integer between 0 and 65534. If 0 is specified, connection attempts do not timeout. 超时值必须是0到65534之间的整数。如果指定0,则连接尝试不会超时。

So your command can become: 因此,您的命令可以变成:

Restore-SqlDatabase `
    -ServerInstance $server `
    -Database "Test" `
    -BackupFile "H:\SQLBACKUP\DATABASE_Refresh\Test_Latest.BAK" `
    -ReplaceDatabase `
    -ConnectionTimeout 0

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM