Invoke-Sqlcmd를 사용하여 SQL Server에 연결이 실패하면 PowerShell에서 오류를 catch하는 데 문제가 있습니다. 나는 다음과 같은 오류가Powershell catch catch invoke-sqlcmd
CLS
$server = "Localhost\fake"
try
{
Invoke-Sqlcmd -Query "SELECT DB_NAME() as [Database]" -Server $server
}
catch
{
Write-Host "Error connecting to server " $server
}
:이 문제를 설명하는 몇 가지 일반적인 코드
Invoke-Sqlcmd : 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 to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
나는 한 줄의 문장 얻기 위해 기다리고 있었다 :
"오류가 서버 로컬 호스트 \ 가짜 연결을"
나는 powershell v3을 사용하고 있으며 사용자 코드가 사용자 정의 오류를 제공합니다. –
또한 powershell v2에서 –
고마워, 알아두면 분명히, 나는 아직도 2에있어. –