Quantcast
Channel: SQLServerCentral » Programming » Powershell » Latest topics
Viewing all articles
Browse latest Browse all 467

capture invalid connection

$
0
0
Hi How to capture invalid connection with powershell?$conn = "MyServer\InstanceThatDoesNotExist"try { $serverInstance = New-Object Microsoft.SqlServer.Management.Smo.Server ($conn) ; $serverInstance.Databases.Count;}catch { $err = $Error[0].Exception ; write-host "Error caught: " $err.Message ; continue ; } ; I want to capture standard error "A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured "

Viewing all articles
Browse latest Browse all 467

Trending Articles