$connectionString = "Data Source=iaosd;Initial Catalog=fasdasd;User ID=sdfsdfsfd;Password=sd0fuisdofij;Connect Timeout=60"
$timer = [Diagnostics.Stopwatch]::StartNew()
# test db connectivity
try {
$sqlConnection = New-Object System.Data.SqlClient.SqlConnection -ErrorAction Stop
$sqlConnection.ConnectionString = $connectionString
$sqlConnection.Open()
$sqlConnection.Close()
Write-Host "connection successful"
} catch {
Write-Host "ERROR"
}
$timer.stop()
Write-Host $timer.Elapsed
Hi, This code actually works immediately if $dbServer is localhost and the other details are correct. But when I change the $dbserver to some random text it takes around 1 minute to complete and it crashes my gui. If I don't put any text in $dbServer the try catch works as expected
"Exception calling "Open" with "0" argument(s): "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible
CategoryInfo : NotSpecified (:) [], MethodInvocationException
Fully QualifiedErrorId : SqlException "