在表格模型部署期间如何传递数据源的凭据?

时间:2018-10-09 23:50:29

标签: deployment ssas ssas-tabular

问题: 当我使用部署向导部署表格模型时。工作正常。但是我们的问题是我们有20个数据源,并且在部署时,我们需要提供20次凭据,因为它要求每个数据源都提供凭据。这是非常痛苦的。这就是为什么我们要自动化部署。

方法: 我遵循了本文https://notesfromthelifeboat.com/post/analysis-services-1-deployment/,并且当我刷新模型时,能够无错误地部署表格模型。失败并显示以下错误

无法将修改保存到服务器。返回错误:'OLE DB或ODBC错误:

The credentials provided for the File source are invalid. (Source at \\share\acaidatatempshare\data\lumeneventpropertiesexport.tsv.).
OLE DB or ODBC error: The command has been canceled..
OLE DB or ODBC error: The command has been canceled..
OLE DB or ODBC error: The command has been canceled..

我的数据源是tsv文件,下面是model.bim文件的数据源部分。如您所见,它没有将凭据的密码保存在model.bim,asdatabase或xmla文件中。

….
….
      {
        "type": "structured",
        "name": "File/\\\\Share\\AcaiDataTempShare\\Data\\LumenEventPropertiesExport tsv",
        "connectionDetails": {
          "protocol": "file",
          "address": {
            "path": "\\\\share\\AcaiDataTempShare\\Data\\LumenEventPropertiesExport.tsv"
          },
          "authentication": null,
          "query": null
        },
        "credential": {
          "AuthenticationKind": "Windows",
          "kind": "File",
          "path": "\\\\Share\\acaidatatempshare\\data\\lumeneventpropertiesexport.tsv",
          "Username": "domain\\username"
        },
        "contextExpression": [
          "let",
          "    #\"0001\" = Csv.Document(..., [Delimiter = \"#(tab)\", Columns = 3, Encoding = 1252, QuoteStyle = QuoteStyle.None]),",
          "    #\"0002\" = Table.TransformColumnTypes(#\"0001\", {{\"Column1\", type text}, {\"Column2\", type text}, {\"Column3\", type text}})",
         "in",
          "    #\"0002\""
        ]
      },
…..
…..

如何在部署过程中以编程方式传递数据源的凭据?

2 个答案:

答案 0 :(得分:1)

不幸的是,在部署模型时,结构化(也称为Power Query)数据源凭据不会保留。我前一段时间在产品团队中报告这是一个错误,但尚未得到答复。如果可以的话,请考虑改用旧版(即提供程序)数据源,因为这些数据源可保留部署之间的凭据。

或者,您可以使用TMSL "createOrReplace" script以编程方式应用密码。创建脚本等最简单的方法是,连接到SSMS中的Analysis Services,右键单击连接(也就是数据源),然后选择“脚本连接为”>“创建或替换为”>“新建查询编辑器”窗口”。在生成的脚本中,确保正确设置了密码:

{
  "createOrReplace": {
    "object": {
      "database": [...] ,
      "dataSource": "File/\\\\Share\\AcaiDataTempShare\\Data\\LumenEventPropertiesExport tsv"
    },
    "dataSource": {
    [...]
    "credential": {
      "AuthenticationKind": "Windows",
      "kind": "File",
      "path": "\\\\Share\\acaidatatempshare\\data\\lumeneventpropertiesexport.tsv",
      "Username": "domain\\username",
      "Password": "<<< YOUR PASSWORD HERE >>>"
    },
    [...]
  }

然后,您可以在部署管道中调用此脚本,例如使用PowerShell Invoke-AsCmd cmdlet。

答案 1 :(得分:1)

这是我最终创建的最终脚本。

# Get tools path
$msBuildPath = Get-MSBuildToPath
$Microsoft_AnalysisServices_Deployment_Exe_Path = Get-Microsoft_AnalysisServices_Deployment_Exe_Path

# BUild smproj 
& $msBuildPath $projPath "/p:Configuration=validation" /t:Build

Get-ChildItem $binPath | Copy -Destination $workingFolder -Recurse

$secureStringRecreated = ConvertTo-SecureString -String $AnalysisServerPassword -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($AnalysisServerUserName, $secureStringRecreated)
#$plainText = $cred.GetNetworkCredential().Password

#region begin Update Model.deploymenttargets
# Read Model.deploymenttargets
[xml]$deploymenttargets = Get-Content -Path  $deploymenttargetsFilePath

$deploymenttargets.DeploymentTarget.Database = $AnalysisDatabase
$deploymenttargets.DeploymentTarget.Server = $AnalysisServer
$deploymenttargets.DeploymentTarget.ConnectionString = "DataSource=$AnalysisServer;Timeout=0;UID=$AnalysisServerUserName;Password=$AnalysisServerPassword;"
$deploymenttargets.Save($deploymenttargetsFilePath);
#endregion

#region begin Update Model.deploymentoptions
# Read Model.deploymentoptions
[xml]$deploymentoptions = Get-Content -Path  $deploymentoptionsFilePath

# Update ProcessingOption to DoNotProcess otherwise correct xmla file wont be generated.
$deploymentoptions.Deploymentoptions.ProcessingOption = 'DoNotProcess'
$deploymentoptions.Deploymentoptions.TransactionalDeployment = 'false'
$deploymentoptions.Save($deploymentoptionsFilePath);
#endregion

# Create xmla deployment file.
& $Microsoft_AnalysisServices_Deployment_Exe_Path $asdatabaseFilePath  /s:$logFilePath  /o:$xmlaFilePath

#region begin Update .xmla
#Add passowrd in .xmla file.
$xmladata = Get-Content -Path $xmlaFilePath | ConvertFrom-Json

foreach ($ds in $xmladata.createOrReplace.database.model.dataSources){
    $ds.Credential.AuthenticationKind = 'Windows'
    $ds.Credential.Username = $AnalysisServerUserName

    #Add password property to the object.
    $ds.credential | Add-Member -NotePropertyName Password -NotePropertyValue $AnalysisServerPassword
}

$xmladata | ConvertTo-Json -depth 100 | Out-File $xmlaFilePath
#endregion

#Deploy model xmla.
Invoke-ASCmd -InputFile $xmlaFilePath -Server $AnalysisServer -Credential $cred`enter code here`