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

执行Read-SQLTableData报错,请求修正PowerShell命令语法

PowerShell读取SQL表数据报错修正

执行以下PowerShell命令读取SQL表数据时触发ItemNotFoundException错误:

$TableNames = Read-SQLTableData 
                  -ServerInstance $SrcServer 
                  -DatabaseName $SrcDatabase 
                  -SchemaName "dbo" 
                  -TableName "EntityMapping.MappingType"

错误信息:

At line:4 char:15
... ableNames = Read-SQLTableData -ServerInstance $SrcServer -DatabaseNam ...
CategoryInfo : ObjectNotFound: (:) [Read-SqlTableData], ItemNotFoundException
FullyQualifiedErrorId : InvalidObjectError,Microsoft.SqlServer.Management.PowerShell.ReadSqlTableData

错误原因与修正方案

错误核心是命令无法定位到指定的表对象,问题出在表名与架构名的参数传递逻辑上:

  • 场景1:EntityMapping是表的架构名,而非表名的一部分
    你错误地将架构名写在了-TableName参数中,同时指定了错误的dbo架构。修正后的命令:
    $TableNames = Read-SQLTableData 
                      -ServerInstance $SrcServer 
                      -DatabaseName $SrcDatabase 
                      -SchemaName "EntityMapping" 
                      -TableName "MappingType"
    
  • 场景2:表确实归属dbo架构,且表名本身包含.(即表名为EntityMapping.MappingType)
    需要用方括号包裹表名,避免PowerShell将.解析为架构与表的分隔符:
    $TableNames = Read-SQLTableData 
                      -ServerInstance $SrcServer 
                      -DatabaseName $SrcDatabase 
                      -SchemaName "dbo" 
                      -TableName "[EntityMapping.MappingType]"
    

内容的提问来源于stack exchange,提问作者Sushmitha shetty

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.25 02:07:09