by antonela at 2013-03-22 03:42:02
I use sqlcmd -S $Server -d db -b -Q “EXEC pr_prova” >>"$FileLog"by antonela at 2013-03-22 06:19:49
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?
$SqlCatalog = â€œmasterâ€
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = â€œServer = $SqlServer; Database = $SqlCatalog; Integrated Security = Trueâ€
if($SqlConnection.state -eq â€œOpenâ€)
echo â€œ$sqlserver â€“ Connection established db=$SqlCatalog : $(get-date -format yyyy.MM.dd-HH.mm.ss)â€ >> $FileLog
echo â€œ$sqlserver â€“ No connection db=$SqlCatalog : $(get-date -format yyyy.MM.dd-HH.mm.ss)â€ >> $FileLog
But how could I read the value of my Sqlserver ($SqlServer) from an .ini file?