问题
Its obvious that we need to import the data from a data source into a model of SSAS tabular.
Imagine we have two data sources connections for two different environments ENV1 and ENV2. Both environment contains same tables but with different data.
Is it possible if I want to switch to ENV2 while I am working on ENV1 in SSAS tabular. Is there any alternative available for this requirement?
Thanks in advance,
Lalith Varanasi.
回答1:
It sounds like you want to have one data source, but to update the connection string based on the environment you deploy to.
I have built a CI/CD process for our tabular models which uses the TOM library in a powershell script to read the .bim file, modify the connection strings based on the environment we are deploying to, create partitions as needed as well as the administrative roles. I can't share the full script at the moment because there are a few references specific to my company, but basically:
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()
回答2:
On your BIM model you can change your datasource connection string.
Go to Model > Existing connection > Modify or use your Tabular Explorer and change your datasource
-> You need to process your tables after this change.
Is it what you are searching?
Have a nice day, Arnaud
回答3:
If you're using Tabular Editor, there's a simple option to prevent connection strings from being deployed, in the "Deployment Wizard" under "Model" > "Deploy..."
By default, "Deploy Connections" is unchecked, meaning that the connection strings used on the target database will be left unchanged, regardless of what you're using in your development database.
来源:https://stackoverflow.com/questions/47202008/ssas-tabular-switch-among-the-datasource-connections