1

I have a stored procedure which populates a few tables in a db which is the data source for a tabular SSAS cube. I want to process the cube as a final step in the stored procedure when I am done loading the tables. I found this code:

DECLARE @XMLA XML = '
  <Batch xmlns="http://schemas.microsoft.com/analysisservices/2003/engine">
    <Process>
      <Object>
        <DatabaseID>' + @Database + '</DatabaseID>
      </Object>
      <Type>ProcessFull</Type>
      <WriteBackTableCreation>UseExisting</WriteBackTableCreation>
    </Process>
  </Batch>
';

DECLARE @Command VARCHAR(MAX) = CONVERT(VARCHAR(MAX), @XMLA);
EXEC (@Command) AT SSAS;

Which accepts a database name, but what I cant figure out is how to make it run on a particular server or SSAS instance. My stored procedure and cube are on different named instanceS of Sql server. Does anyone know how to either embed the server/instance name in the xmla or run the xmla on a specified instance?

Thanks in advance.

1
  • I would create a sql agent job and then run the job from the stored proc. BTW TMSL is the way forward for Tabular cubes Commented Nov 17, 2020 at 4:42

2 Answers 2

1

I discovered that the key is using a linked server (and TMSL, thanks Mitch Wheat):

DECLARE @TMSL VARCHAR(MAX) = '{
  "refresh": {
    "type": "full",
    "objects": [
      {
        "database": ' + @DataBaseName + '
      }
    ]
  }
}';
 

EXEC (@TMSL) AT SSASTABULAR; -- linked server name

SSASTABULAR is a linked server pointing to my ssas cube server instance.

Sign up to request clarification or add additional context in comments.

1 Comment

rather than use a linked server, I think a cleaner approach is to create an agent job, and then run that job from SP
-2

You can create a job in SQL Agent to process the cube. You can then call the SQL Agent job from your stored procedure using sp_start_job.

https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-start-job-transact-sql?view=sql-server-ver15

Doing it this way allows you to process the cube from different stored process without having to store the processing code in each one of them. It also makes it easier to update incase your cubes are moved to a different server. You only have to update the SQL Agent Job to point to the new server.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.