sqldatareader is not reading rows when placed inside while loop construct . there is one row returned from the from the sql query which I verfied in DB. when I read it simply without any construct , its reading the data. The following code peice when placed above the while loop construct gives me data in the log file. while loop will not get activated as there is only one row and that is ok.
$sqloutqryreader = MsSqlQueryExecutor -SqlQuery $SqlQuery -logfile $logfile
$sqloutqryreader.Read()
$InputFileLst = $sqloutqryreader["InputFiles"]
Add-Content -Value "$TimeinSec Log: Reading data from sql reader $InputFileLst" -Path $logfile
$rdrRowCnt = 0
while($sqloutqryreader.Read())
{
$rdrRowCnt++
if($rdrRowCnt -gt 1)
{
Add-Content -Value "$TimeinSec Ambiguity: two Records are found for the current job: $jobname in the $mastTableNm table, hence aborting" -Path $logfile
exit
}
$InputFileLst = $sqloutqryreader["InputFiles"].Split(";")
$OutputFileLst = $sqloutqryreader["OutputFiles"].Split(";")
Add-Content -Value "$TimeinSec Log: Input files:$InputFileLst and outputfiles:$OutputFileLst found for the current job: $jobname in the $mastTableNm table" -Path $logfile
}
however when i place the following while loop construct, while loop is not activated. Since there is one row, it has to get activated.
$sqloutqryreader = MsSqlQueryExecutor -SqlQuery $SqlQuery -logfile $logfile
$rdrRowCnt = 0
while($sqloutqryreader.Read())
{
$rdrRowCnt++
if($rdrRowCnt -gt 1)
{
Add-Content -Value "$TimeinSec Ambiguity: two Records are found for the current job: $jobname in the $mastTableNm table, hence aborting" -Path $logfile
exit
}
$InputFileLst = $sqloutqryreader["InputFiles"].Split(";")
$OutputFileLst = $sqloutqryreader["OutputFiles"].Split(";")
Add-Content -Value "$TimeinSec Log: Input files:$InputFileLst and outputfiles:$OutputFileLst found for the current job: $jobname in the $mastTableNm table" -Path $logfile
}
$sqloutqryreader.Read()return$trueor1(or any other output that is not0\$null\$false)? Elsewhile($sqloutqryreader.Read())won't happen.