Microsoft.AnalysisServices.Tabular.JsonScripter 问题

Microsoft.AnalysisServices.Tabular.JsonScripter Issue

我正在尝试在我的 Powershell 脚本中调用 Microsoft.AnalysisServices.Tabular.JsonScripter 以自动为 SSAS 表格生成 CreateOrReplace 数据库脚本。但我不断收到以下错误。

Exception calling "ScriptCreateOrReplace" with "1" argument(s): "Could not load file or assembly
'Microsoft.AnalysisServices.AppLocal.Tabular.Json, Version=14.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'
or one of its dependencies. The system cannot find the file specified."
At C:\Desktop\json.ps1:10 char:1
+ [Microsoft.AnalysisServices.Tabular.JsonScripter]::ScriptCreateOrRepl ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException

这是我正在测试的代码:

Import-Module SqlServer
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices.Tabular");
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices.Core");
$tab = "server";
$dbId = "database";
$as = New-Object Microsoft.AnalysisServices.Tabular.Server;
$as.Connect($tab);
$db = $as.Databases[$dbId];

[Microsoft.AnalysisServices.Tabular.JsonScripter]::ScriptCreateOrReplace($db);

程序集加载以下内容:

GAC    Version        Location
---    -------        --------
True   v4.0.30319     C:\windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.AnalysisServices.Tabular\v4.0_14.0.0.0__8...
True   v4.0.30319     C:\windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.AnalysisServices.Core\v4.0_14.0.0.0__8984...

所以程序集应该被识别,但它却抱怨它们。这种情况我该怎么办?

我认为问题在于 SqlServer 模块似乎正在加载它自己的 "AppLocal" 版本的 AMO 程序集。如果您从脚本中删除第一行,它应该可以工作。您还可以按如下方式简化它以仅加载主 AMO 程序集(这将根据需要加载任何其他依赖项)并仅使用 Microsoft.AnalysisServices.Server 连接而不是表格特定的 class.

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices");

$tab = "localhost\tab17";

$dbId = "testing";

$as = New-Object Microsoft.AnalysisServices.Server;

$as.Connect($tab);

$db = $as.Databases[$dbId];

[Microsoft.AnalysisServices.Tabular.JsonScripter]::ScriptCreateOrReplace($db);