代码之家  ›  专栏  ›  技术社区  ›  mystack

使用powershell在远程计算机上运行SQL文件

  •  0
  • mystack  · 技术社区  · 5 年前

    通过powershell执行SQl脚本(ddl、SQl)的最佳方式是什么。

    我正在使用下面的命令行来执行脚本。

     Invoke-Sqlcmd -InputFile "C:\filepath\file1.ddl" -ServerInstance "10.166.23.28" -Database "DB1" -Username "sa" -Password "Pass01" -ConnectionTimeout 1000 | Out-File -FilePath "C:\scriptsout\TestSqlCmd.txt"
    

    它是通过抛出以下错误而出错的

        Invoke-Sqlcmd : Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or theserver is not responding.
    

    当我执行“从表名中选择*”命令时,它正在工作并将输出写入输出文件

    0 回复  |  直到 5 年前
        1
  •  0
  •   mystack    5 年前

    我可以使用以下命令执行它

    Invoke-Sqlcmd -InputFile "C:\filepath\file1.ddl" -ServerInstance "10.166.23.28" -Database "DB1" -Username "sa" -Password "Pass01" -ConnectionTimeout 100 -QueryTimeout 0 -verbose *> "C:\filepath\File1.log"
    

    通过将QueryTimeout设置为零,编译器将无限期等待,直到脚本执行完成。此外,将Verbose设置为*有助于最大化日志记录,并防止日志显示在命令提示符窗口中。

    推荐文章