开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜