views:

224

answers:

2

Hi everyone.

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 successful. Any ideas why this would be - shouldn't the exitcode be 0 if successful?

Thanks!

A: 

Sorry - it was an error.

Ev
A: 

dont you mean - user error

Jimmy