I use sqlcmd -S $Server -d db -b -Q "EXEC pr_prova" >>"$FileLog" in a file.ps1, but before to do this command I would like to verify if the connection was successfully established with sql server.
If so, I go ahead and launch my stored procedure using my sqlcmd-..........., If not, I want to exit from my file.ps1 (and return an errorr). How can I do to write in a log file ($FileLog) that the connection with db was\wasn't ok?
At the end of a cmd I used exit /B %errorlevel% to return the result of my job.This value is get in input from another software which uses it to set an indicator. If I use $? can I have the same result?