0
我希望有一个尾随.....在运行时扩展/增长SqlConnection.Open()
。在SqlConnection.Open()运行时运行写主机输出
我不知道如何做到这一点,当我运行命令SqlConnection.Open()
直到连接成功,然后我的代码继续,输出停止。
我尝试了一个while循环,但while内容什么也没做,直到实际连接建立或失败,这可能需要10-15秒。
$waiting = ".", ".", ".", ".", ".";
Try
{
#write-host -ForegroundColor GREEN "Connecting to SQL Server: $svr"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $svr ;Database = $db; User ID = $uid ;Password = $pwd;"
while (!$SqlConnection.State -eq 'Open')
{
write-host -ForegroundColor GREEN "Connecting to SQL Server: $svr" -NoNewline
ForEach ($p in $waiting) {
Write-Host -ForegroundColor Cyan "`r$p" -NoNewLine
Start-Sleep -Milliseconds 300
}
$SqlConnection.Open()
}
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.Connection = $Global:SqlConnection
$SqlCmd.CommandText = $UsrSqlQuery
}
您可以向我们显示迄今为止的相关代码吗? – user2366842
这就是我目前所处的位置,有一些while和其他while循环 – catalyph