Execute a Job using T-SQL on a SSAS Cube
Question
I'm trying to execute a SQL job using T-SQL in my application on a SSAS cube. Here is what I have got so far:
public void UpdateCube()
{
AdomdConnection conn3 = new AdomdConnection("Data Source=BTN-SQL1;Initial Catalog=BTNTurboAnalysisServices;");
conn3.Open();
AdomdCommand cmd = conn3.CreateCommand();
cmd.CommandText = "EXEC [SalesAnalysis].sp_start_job N'Process BTN SSAS'; GO";
cmd.ExecuteNonQuery();
conn3.Close();
}
[SalesAnalysis] is the name of my cube and 'Process BTN SSAS' is the name of my SQL job.
The error I receive is:
Query (1, 6) Parser: The syntax for '[SalesAnalysis]' is incorrect.
Any help would be appreciate, thanks!
Solution
sp_start_job is a stored procedure in master.dbo try
exec master.dbo.sp_start_job N'Process BTN SSAS'; GO";
Also, as master.dbo.sp_start_job is a SQL stored procedure, you'll need to use a SQL connection with ADO.NET (System.Database.SQLClient.SQLConnection) to kick it off, not ADOMD. As sp_start_job just kicks off SQLAgent jobs, you'll need to make sure it's running as well.
There are some methods in ADOMD that allow you to process cubes, but I can't recall them off the top of my head.
Something like
Server server = new Server();
server.Connect(cubeConnectionString);
Database database = server.Databases.FindByName(databaseName);
Cube cube = database.Cubes.FindByName(cubeName);
cube.Process(ProcessType.ProcessFull);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow