Using ASCMD to run command line scripts for SSAS

Problem

Sometimes it would be helpful to run scripts from a command line for Analysis Services. This would be useful for things like creating backups, processing data or running other tasks. Is there a command line tool like sqlcmd for multidimensional databases and Data Mining?

Solution

ASCMD is the command line tool used not only for Multidimensional databases, but also for Data Mining projects. You can run MDX, DMX and XMLA scripts using this tool. In this example I will show how to backup a Multidimensional Database created in Analysis Services using ascmd.

Requirements

ASCMD is not installed by default.

For this tip, I am assuming that you already have a multidimensional database created.

Getting Started

In this example, we are going to create an Analysis Services Database Backup using ascmd. For this purpose, let’s create the backup script first using SQL Server Management Studio.

  1. Open SQL Server Management Studio and start an Analysis Services Project.
    Open the SQL Server Management Studio
  2. Right click on the database that you want to backup and select the Back Up… option.
    Backup the Multidimentional Database
  3. Specify the path where you want to store the backup. In this example we will store the backup on the “C:\” drive and the backup file will be  named “Analysis Services Tutorial.abf”. In this example, I removed the “Encrypt backup file” option.
    Specify the backup path and options
  4. Click on the Script option and select “Script Action To New Query Window” and close the Backup Database window. The script option generates the backup code using XMLA. XMLA is a XML extension used in Analysis Services.
    Script Action to New Query Window
  5. Now, we are going to save the script. Go to File > Save XMLAQuery1.xmla As…
    Save the script in a different path.
  6. Specify the path of the script and the file name. In this example the path will be the “C:\” drive and the name will be “backupMD.xmla”.
    Save the file as
  7. We are almost finished. Now to run the command line, go to the path where you copied and pasted the ascmd.exe file. In this example, I copied it to the C:\Program Files\Microsoft SQL Server\100\Tools\Binn folder.
  8. Run the following command:
    ascmd -S -i c:\backupMD.xmla
    Use the ascmd

    Command options:

    • ASCMD is the command
    • -S is used to specify the SQL Server Name (if not specified uses the local server)
    • -i is used to specify the input file, in this case we are running the “backupMD.xmla” script.

    To verify that the backup was created, check to see that the “Analysis Services Tutorial.abf” file was created on the C:\ drive.

Next Steps

Leave a Reply

Your email address will not be published. Required fields are marked *