Моя цель - подключиться к SQL-серверу с защищенным паролем. Ниже мой сценарий, но он не прошел. Кто-нибудь может определить, что такое ошибка? Я проверил имя экземпляра правильно. сообщениеПодключение к SQL Server через защищенный пароль
$Path = "D:\AdminStuff\PowerShell\Password\Password.txt"
$uid = 'sa'
$pwd = Get-Content D:\AdminStuff\PowerShell\Password\Password.txt |
ConvertTo-SecureString
$pwd.MakeReadOnly()
$creds = New-Object System.Data.SqlClient.SqlCredential($uid,$pwd)
$con = New-Object System.Data.SqlClient.SqlConnection
$con.ConnectionString = "Server=SLB-CLMFZ52\MSSQLSERVER;Database=master;"
$con.Credential = $creds
$con.Open()
Write-Host "--------------------------------------------------------"
Write-Host "Connection String : "
Write-Host $server.ConnectionContext.ConnectionString
Write-Host "--------------------------------------------------------"
$con.Close()
Ошибка.
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. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid)" At D:\AdminStuff\PowerShell\Password\Testing.ps1:12 char:10 + $con.Open <<<<() + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
Вы проверили, что вы действительно можете подключиться к серверу в первую очередь? –