sql - 获取表格数据库的连接数据源
问题描述
使用 SQL2017 版本 14.0.1.439。我需要使用 Powershell 更改表格数据库中连接的数据源路径。
这是我的代码:
$ServerName="localhost\tabular"
$loadInfo =
[Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices")
$server = New-Object Microsoft.AnalysisServices.Server
$server.connect($ServerName)
if ($server.name -eq $null) {
Write-Output ("Server '{0}' not found" -f $ServerName)
break
}
foreach ($d in $server.Databases )
{
Write-Output ( "Database: {0}; Status: {1}; Size: {2}MB; Data Sources: {3} " -f $d.Name, $d.State, ($d.EstimatedSize/1024/1024).ToString("#,##0"), $d.DataSources.Count )
}
我的问题是 $d.DataSources.Count 始终为 0。
我正在寻找一些用PS编辑它的方法。
解决方案
您应该通过Model.Datasources
我可以确认以下代码返回我的表格模型的数据源数量来访问数据源。
$ServerName="localhost\tabular"
$loadInfo =
[Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices")
$server = New-Object Microsoft.AnalysisServices.Server
$server.connect($ServerName)
if ($server.name -eq $null) {
Write-Output ("Server '{0}' not found" -f $ServerName)
break
}
foreach ($d in $server.Databases )
{
Write-output ( "Database: {0}; Status: {1}; Size: {2}MB; Data Sources: {3} " -f $d.Name, $d.State, ($d.EstimatedSize/1024/1024).ToString("#,##0"), $d.Model.DataSources.Count )
}
推荐阅读
- google-sheets - 填写后如何按计划导出所有数据放置另一张表
- python - 在 Python 中将操作分配给类中的特殊字符
- swift - 如何使用 UNIX 域套接字在 Swift 中设置 IPC
- swiftui - SwiftUI AppDelegate didRegisterForRemoteNotificationsWithDeviceToken 从未调用
- adobe-documentgeneration - $formatNumber 在表数组中使用时输出 NaN
- php - 如何检查文件名,如果存在,则添加计数器
- javascript - 使用 JavaScript 和 jQuery 对 div 中的输入和返回值求和
- python - 我无法安装任何 python 包
- r - Dplyr:如何匹配来自多列的值?
- git - 在每个环境中使用分支时避免冲突的分支流程应该是什么