开发者

SQLCMD, when called from Powershell, returns ExitCode == 1, even if successful

开发者 https://www.devze.com 2022-12-19 16:25 出处:网络
I have a Powershell script that calls sqlcmd to run a sql script that backs up a database: function RunSqlScriptWithErrorMessage

I have a Powershell script that calls sqlcmd to run a sql script that backs up a database:

function RunSqlScriptWithErrorMessage
{
    param([string]$sqlServer, [string]$sqlUserName, [string]$sqlPassword, [string]$scriptName, [string]$errorMessage)

    $commandName = "sqlcmd"
    $startInfo = New-Object Diagnostics.ProcessStartInfo($commandName)
    $startInfo.UseShellExecute = $false
    $startInfo.Arguments = "-S $sqlServer -U $sqlUserName -P $sqlPassword -i `"${sqlScriptName}`""
    $process = [Diagnostics.Process]::Start($startInfo)
    $process.WaitForExit()
    $exitCode = $process.ExitCode
    if($exitCode -ne 0 ) { throw $errorMessage}
}

The strange thing is that process.ExitCode == 1 even though the back up is succes开发者_如何学编程sful. Any ideas why this would be - shouldn't the exitcode be 0 if successful?

Thanks!


Sorry - it was an error.

0

精彩评论

暂无评论...
验证码 换一张
取 消