免责声明:我是Powershell的新手。
我正在尝试使用从Powershell运行的SQL脚本编写两个SQL Server Express数据库的备份的脚本。当我从SSMS运行SQL时,它运行良好且没有超时。当我从Powershell脚本运行SQL时,小型数据库备份成功,但是较大的数据库备份失败,并显示以下错误:
Invoke-Sqlcmd : Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
At C:\Program Files\DBBackups\dbfull_backup.ps1:5 char:1
+ Invoke-Sqlcmd -ServerInstance "$serverInstance" -InputFile "C:\Program Files\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Invoke-Sqlcmd], SqlPowerShellSqlExecutionException
+ FullyQualifiedErrorId : SqlError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand
Run Code Online (Sandbox Code Playgroud)
这是带有Invoke-SqlCmd的.ps1脚本的第5行:
Invoke-Sqlcmd -ServerInstance "$serverInstance" -InputFile "C:\Program Files\DBBackups\dbfull_backups.sql" -Variable $sqlVariable -Verbose *> $outputFile
Run Code Online (Sandbox Code Playgroud)
这是来自SQL的BACKUP命令:
BACKUP DATABASE FrameStore TO DISK = @framestore_backup_file;
Run Code Online (Sandbox Code Playgroud)
通过Powershell / Invoke-Sqlcmd运行时的超时与从SSMS运行时的超时不同吗?在SSMS中运行时,备份需要不到3分钟的时间,因此与我在docs.microsoft文档中看到的10分钟的数字不太接近。这是在SSMS中运行时的备份输出:
BACKUP DATABASE successfully processed 467003 pages in …Run Code Online (Sandbox Code Playgroud)