Deploying Analysis Services Models

This document provides a comprehensive guide to deploying your SQL Server Analysis Services (SSAS) models to a production or staging environment. Deployment involves transferring your model metadata and data from a development environment to a server where users can access it.

Deployment Methods

There are several ways to deploy SSAS models, each with its own advantages:

Deploying from Visual Studio (SSDT)

This is the recommended and most straightforward method for developers.

  1. Open your SSAS project in Visual Studio with SQL Server Data Tools.
  2. In Solution Explorer, right-click on the SSAS project and select Deploy.
  3. The SSAS Deployment Wizard will launch.
  4. In the Deployment Target page, specify the Server name and Database name for your target SSAS instance.
  5. Configure Deployment Options: You can choose to overwrite the existing database, process data after deployment, or create a new database.
  6. Review the deployment summary and click Finish to start the deployment process.

A successful deployment will transfer your model to the specified Analysis Services server.

Using XMLA Scripts for Deployment

XMLA scripts offer greater flexibility and are ideal for automation and complex deployment scenarios.

You can generate XMLA scripts from your SSAS project in Visual Studio by:

  1. Right-clicking the project and selecting Generate Deployment Script. This creates an XMLA file (typically named `YourProjectName.asdatabase`).
  2. Alternatively, you can write custom XMLA scripts to create, alter, or process SSAS databases.

To execute an XMLA script:


<Batch xmlns="http://schemas.microsoft.com/analysisservices/2003/engine" Transaction="true">
  <Create>
    <Database Folder="C:\Program Files\Microsoft SQL Server\MSAS15.MSSQLSERVER\OLAP\Data" ID="MyNewCubeDB"/>
  </Create>
  <Alter AllowOverwrite="true" ObjectExpansion="ExpandFull">
    <DatabaseID>MyNewCubeDB</DatabaseID>
    <ObjectDefinition>
      <Database xmlns="http://schemas.microsoft.com/analysisservices/2003/engine" xmlns:db="http://schemas.microsoft.com/analysisservices/2003/engine/database">
        <Name>MyNewCubeDB</Name>
        <DataSourceViews>
          <!-- ... DataSourceView definitions ... -->
        </DataSourceViews>
        <Cubes>
          <!-- ... Cube definitions ... -->
        </Cubes>
      </Database>
    </ObjectDefinition>
  </Alter>
</Batch>
            

Deployment Considerations

Always consider the target environment (development, staging, production) and plan your deployment strategy accordingly. Use parameter binding in Visual Studio to handle environment-specific connection strings and configurations.

Processing Analysis Services Models

After deployment, your SSAS model typically needs to be processed to load data from the data sources. Processing can be done:

Processing Types:

Automating Deployments with PowerShell

For continuous integration and continuous delivery (CI/CD) pipelines, PowerShell is invaluable.

The SQL Server Analysis Services cmdlets for PowerShell allow you to:

Example PowerShell snippet for deployment:


Import-Module SQLServer

$server = New-Object Microsoft.AnalysisServices.Tabular.TabularConnection
$server.Connect("YourServerName")

$deploymentFile = "C:\Path\To\YourDatabase.asdatabase"
$server.Deploy($deploymentFile, "TargetDatabaseName", $true) # $true for process after deploy

Write-Host "Deployment completed successfully."
            

For more advanced scenarios, explore the cmdlets for managing partitions, dimensions, and cubes.