onu*_*ade 5 sql-server powershell
将 SQLPS 连接到 SQL Server 时,它会尝试运行一些 WMI 服务状态查询。在没有权限的环境中,PowerShell 会发出一堆警告,并且连接速度非常慢。
可以使用 $WarningPreference = 'SilentlyContinue' 来抑制警告消息,但有没有办法禁用实际检查,以提高性能?
例子:
PS SQLSERVER:\> set-location \sql\myserver\default
WARNING: Could not obtain SQL Server Service information. An attempt to connect to WMI on '<servername>' failed with the following error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
WARNING: Could not obtain SQL Server Service information. An attempt to connect to WMI on '<servername>' failed with the following error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
WARNING: Could not obtain SQL Server Service information. An attempt to connect to WMI on '<servername>' failed with the following error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
WARNING: Could not obtain SQL Server Service information. An attempt to connect to WMI on '<servername>' failed with the following error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
WARNING: Could not obtain SQL Server Service information. An attempt to connect to WMI on '<servername>' failed with the following error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
WARNING: Could not obtain SQL Server Service information. An attempt to connect to WMI on '<servername>' failed with the following error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
WARNING: Could not obtain SQL Server Service information. An attempt to connect to WMI on '<servername>' failed with the following error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
WARNING: Could not obtain SQL Server Service information. An attempt to connect to WMI on '<servername>' failed with the following error: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
场景:在执行任何工作之前,使用 PowerShell 作业步骤的 SQL 代理作业需要 30 多秒才能启动并连接到本地 SQL Server。
我发现连接速度慢的主要原因是 Set-Location 命令中的端口号(缺少端口号)。也就是说,对于自定义端口上的默认实例:
Set-Location \sql\$server\default\databases\mydb #very slow
Set-Location \sql\$server`,$port\default\databases\mydb #speedy quick
Run Code Online (Sandbox Code Playgroud)
转义逗号很烦人,但很重要。不确定后端的详细信息,是否对端口造成影响,或者使用浏览器服务解析端口号是否很慢,但提供端口号可以可靠地解决性能问题。
归档时间: |
|
查看次数: |
1467 次 |
最近记录: |