Greetings,
I am using a scripted process for automated individual SQL database restorations, as needed. I am invoking sqlcmd via PowerShell, which performs the restoration by using the following example syntax:
This is simple enough and works, however, I did want to also incorporate some sort of error handling, based on the exitcode generated by the proc being called. I've tried using PowerShell's own $LASTEXITCODE, however, the code generated always appears to be 0, since the script and sqlcmd itself -- technically -- ran successfully, so then it does me no good. The actual first exitcode generated by the sqlbackup proc is ignored.
Might anyone have a method for exitcode handling, in combination with PowerShell, sqlcmd, and the sqlbackup stored procedure? Thanks in advance!
I am using a scripted process for automated individual SQL database restorations, as needed. I am invoking sqlcmd via PowerShell, which performs the restoration by using the following example syntax:
Quote: |
EXECUTE master..sqlbackup '-SQL "RESTORE DATABASE [DB_NAME] FROM DISK = ''FULL_PATH'' WITH RECOVERY, DISCONNECT_EXISTING, REPLACE"' |
This is simple enough and works, however, I did want to also incorporate some sort of error handling, based on the exitcode generated by the proc being called. I've tried using PowerShell's own $LASTEXITCODE, however, the code generated always appears to be 0, since the script and sqlcmd itself -- technically -- ran successfully, so then it does me no good. The actual first exitcode generated by the sqlbackup proc is ignored.
Might anyone have a method for exitcode handling, in combination with PowerShell, sqlcmd, and the sqlbackup stored procedure? Thanks in advance!