[英]Can't execute query to an Azure SQL Server from PowerShell
I have a SQL Azure database and I try to execute the query from PowerShell. 我有一个SQL Azure数据库,我尝试从PowerShell执行查询。
I am using Invoke-Sqlcmd
Command. 我正在使用
Invoke-Sqlcmd
命令。
I get this error message: 我收到此错误消息:
A network related or instance-specific error occurred while establishing a connection to SQL Server.
建立与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.
验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
(提供者:命名管道提供程序,错误:40-无法打开与SQL Server的连接)
But if I connect from Management Studio, everything is OK. 但是,如果我从Management Studio连接,一切正常。
I setup a proper firewall rule. 我设置了正确的防火墙规则。
Does anybody know what may happen? 有人知道会发生什么吗?
On your connection string, specify TCP as the protocol like 在您的连接字符串上,将TCP指定为协议,例如
tcp:mymssqlserver.database.windows.net
Your PowerShell may look then like: 然后,您的PowerShell可能如下所示:
$server = " tcp:mymssqlserver.database.windows.net,1433"
$database = "master"
$adminName = "admin@my-azure-sql"
$adminPassword = "P4SSW0rd"
$connectionString = "Server=$server;Database=$database;User ID=$adminName;Password=$adminPassword;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
$connection = New-Object -TypeName System.Data.SqlClient.SqlConnection($connectionString)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.