【发布时间】:2017-09-25 20:14:27
【问题描述】:
我希望有一个尾随.....在我运行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
}
【问题讨论】:
-
你能告诉我们你到目前为止的相关代码吗?
-
这就是我目前的情况,已经有一些迭代 do while 和其他 while 循环
标签: sql-server powershell while-loop sqlconnection parallel.foreach