You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SqlServer PowerShell Core模块加载失败:无法获取SqlContext类型

问题:PowerShell Core中SqlServer模块连接SQL实例失败

运行本地开发环境搭建脚本时,该脚本依赖SqlServer模块修改SQL配置,执行失败。

执行命令与报错信息

执行以下连接默认SQL实例的命令:

Set-Location SQLSERVER:\SQL
Get-ChildItem

返回警告:

WARNING: Could not obtain SQL Server Service information. An attempt to connect to 'MACHINENAME' failed with the following error: Could not load type 'Microsoft.SqlServer.Server.SqlContext' from assembly 'System.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

模块安装状态

  • 已通过命令Install-Module -Name SqlServer -Scope AllUsers -AllowClobber安装SqlServer模块,并用Import-Module SqlServer加载。
  • 执行Get-Module -ListAvailable确认,版本为21.1.18256的SqlServer模块已加载,路径为C:\Program Files\PowerShell\Modules。

环境情况

  • 该脚本在旧工作电脑可正常运行,但新电脑无法执行,且无法访问旧电脑对比环境。
  • 当前环境信息:
PS C:\> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.3
PSEdition                      Core
GitCommitId                    7.3.3
OS                             Microsoft Windows 10.0.19045
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

疑问

是否是PowerShell Core新版本导致的问题?或是旧电脑存在未被察觉的依赖?目前在Stack Overflow上找到的相关文章均针对.NET Framework应用,不适用于PowerShell Core,已在PowerShell GitHub提交该问题。

内容的提问来源于stack exchange,提问作者Thomas Parikka

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 11:32:56