【问题标题】:SSAS tabular - Switch among the datasource connectionsSSAS 表格 - 在数据源连接之间切换
【发布时间】:2017-11-09 12:35:07
【问题描述】:

很明显,我们需要将数据源中的数据导入到 SSAS 表格模型中。

假设我们有两个数据源连接用于两个不同的环境 ENV1 和 ENV2。两种环境都包含相同的表,但数据不同。

如果我在 SSAS 表格中处理 ENV1 时想切换到 ENV2,是否有可能。是否有任何替代方案可满足此要求?

提前致谢,

拉利斯·瓦拉纳西。

【问题讨论】:

    标签: ssas-tabular


    【解决方案1】:

    听起来您想要一个数据源,但要根据您部署到的环境更新连接字符串。

    我已经为我们的表格模型构建了一个 CI/CD 流程,该流程使用TOM library in 用于读取 .bim 文件的 powershell 脚本,根据我们要部署的环境修改连接字符串,根据需要创建分区以及管理角色。我目前无法分享完整的脚本,因为有一些特定于我公司的参考资料,但基本上:

    try{
    Write-Log "loading Microsoft.AnalysisServices assemblies that we need" Debug
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices.Core") | Out-Null
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.AnalysisServices.Tabular") | Out-Null
    }
    catch{
        Write-Log "Could not load the needed assemblies... TODO: Figure out and document how to install the needed assemblies. (I would start with the SQL feature pack)" Error -ErrorAction Stop
    }
    
    $modelBim = [IO.File]::ReadAllText($bimFilePath)
    $db = [Microsoft.AnalysisServices.Tabular.JsonSerializer]::DeserializeDatabase($ModelBim)
    
    #Our DEV and TEST models get deployed on the same SSAS instance. We have to modify the name of the model to reference which environment they are reading from.
    $db.ID = "$($modelName)_$($TargetEnvironment)"
    $db.Name = "$($modelName)_$($TargetEnvironment)"
    
    Write-host "Updating the data source connections to use the $TargetEnvironment environment."
    foreach ($ds in $db.Model.Model.DataSources){
        Write-Host "Updating connection information for the $($ds.Name) connection" Debug
        #I use a Powershell function called Get-DBServerFromEnvironment which we use to pull the correct server name for each of our different databases. Our database names are the same in each environment, except that they are prefixed with the environment name. 
        #Using this design, DB1,DB2,DB3 is the name of the data source (Say ApplicationOLAP,DataWarehouse,ThirdPartDB) and you set enviornment specific connection strings in a seperate custom function so that the logic is stored in one place 
        switch($ds.Name ){
            "DB1"{$ds.ConnectionString = "EnvironmentSpecificConnectionStringToDB1"}
            "DB2"{$ds.ConnectionString = "EnvironmentSpecificConnectionStringToDB2"}
            "DB3"{$ds.ConnectionString = "EnvironmentSpecificConnectionStringToDB3"}
            "DB4"{$ds.ConnectionString = "EnvironmentSpecificConnectionStringToDB4"}
            default{Write-Log "Unknown Data source name" Warning}
        } 
    }
    
    $server = New-Object Microsoft.AnalysisServices.Tabular.Server
    #$serverName is the SSAS server, I get this by calling a custom function and specifying the target enviornment.
    $server.Connect($serverName)
    $server.BeginTransaction()
    
    if ($server.Databases.Contains($db.ID)){
        Write-Log "Tabular database with the ID: $($db.ID) exists. Dropping and recreating"
    
        $server.Databases.FindByName($db.Name).Drop()
        $server.Databases.Remove($db.ID, [System.Boolean]::TrueString)
        $server.Databases.Add($db) | Out-Null
    }
    else{
        Write-Log "Tabular database with the ID: $($db.ID) does not exist. Creating"
        $server.Databases.Add($db) | Out-Null
    }
    #This part is where you are actually writing your changes to the server. modify as needed.
    $db.Update( "ExpandFull")
    $db.Model.RequestRefresh("Automatic")
    $saveOptions = New-Object Microsoft.AnalysisServices.Tabular.SaveOptions
    $saveOptions.MaxParallelism = 5
    
    Write-Log "Starting the processing at [$([DateTime]::Now)]. The script will hang while the cube is processing."
    $ProcessElapsed = [system.diagnostics.stopwatch]::startnew()
    $result = $db.Model.SaveChanges($saveOptions)
    $impact = $result.Impact
    $xmlaResult = $result.XmlaResults
    
    #TDOD: Check the result for success/failure. 
    Write-Log "Processing took $($ProcessElapsed.Elapsed.ToString()). Hours:Minutes:Seconds:Milliseconds"
    
    $server.CommitTransaction()
    

    【讨论】:

    • 你试过Tabular Editor吗?它基本上是一个围绕 TOM 的 UI,但它也可以用作 CLI application,在 CI/CD 设置中创造奇迹!
    • @Dan,我没有,但我一定会的!谢谢推荐。
    【解决方案2】:

    在您的 BIM 模型上,您可以更改数据源连接字符串。

    转到模型 > 现有连接 > 修改 或使用您的表格资源管理器并更改您的数据源

    ->您需要在此更改后处理您的表格。

    这是您正在搜索的内容吗?

    祝你有美好的一天, 阿诺

    【讨论】:

      【解决方案3】:

      如果您使用Tabular Editor,有一个简单的选项可以防止连接字符串被部署,在“模型”>“部署...”下的“部署向导”中

      默认情况下,“部署连接”未选中,这意味着目标数据库上使用的连接字符串将保持不变,无论您在开发数据库中使用什么。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-05-14
        • 1970-01-01
        • 2011-11-19
        • 2012-05-14
        相关资源
        最近更新 更多