database - powershell invoke-sqlcmd System.Data.DataRow - Stack Overflow

When I run this from the PowerShell command lineInvoke-Sqlcmd -TrustServerCertificate -ServerInstance

When I run this from the PowerShell command line

Invoke-Sqlcmd -TrustServerCertificate -ServerInstance "HELLODANNY\inst0100" 
              -Database "come" -outputas datarows 
              -Query "select count(*) from andplaywithus"   

I get this output in the terminal.

Column1
-------
     74

However when I put the database invocation into a loop

# Define a condition to control the loop
$counter = 0
$maxIterations = 1005  # Number of times to run the query

while ($counter -lt $maxIterations) {
    $result = Invoke-Sqlcmd -TrustServerCertificate -ServerInstance "HELLODANNY\inst0100" -Database "come" -outputas datarows -Query "select count(*) from andplaywithus"
    Write-Host "Result: $($result)"

    # Increment the counter to avoid an infinite loop
    $counter++

    # Optionally add a delay between iterations
    Start-Sleep -Seconds 20
}

I get

Result: System.Data.DataRow

this might work

$result = Invoke-Sqlcmd -TrustServerCertificate -ServerInstance "HELLODANNY\inst0100" -Database "come" -outputas datarows -Query "select count(*)as count from andplaywithus"
    Write-Host "Result: $($result[0].count)"

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744690871a4588202.html

相关推荐

  • database - powershell invoke-sqlcmd System.Data.DataRow - Stack Overflow

    When I run this from the PowerShell command lineInvoke-Sqlcmd -TrustServerCertificate -ServerInstance

    23小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信