Subscribe - It's FREE!!

Stay Connected Here

Stay Updated With Us Here



Google

Process SSAS Cube programmatically in C# using Microsoft.AnalysisServices Dll


Share with WhatsApp


This post covers information about How to Process SSAS (Microsoft SQL Server Analysis Services) Cubes programmatically or dynamically in C#.

I had an opportunity to work on SSAS in one of project in which I had designed Data Warehouse and Cube. Prior to that I had only worked on ASP.NET, MVC and other Web Technologies and SSRS therefore whole process of creating data warehouse and cube then processing cube programmatically was very new and learning experience for me.  For this I did some R&D and search on google so thought good to share the code at one place which I finally used (posts on several sites was really helpful to make this code work)

First you need to know about Microsoft.AnalysisServices.dll

Microsoft.AnalysisServices.dll is an Analysis Management Object API provided by Microsoft, which is used to administer Analysis Services instances. (MSDN Link)

If you have installed SQL server 2008 R2 then you can find this DLL at below path (path can be different as per operating system version and bit type).

C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\SQLServer2008R2\x64\Microsoft.AnalysisServices.DLL

you need to reference it in your project. (I have set CopyLocal property to true after referencing it as it will always copy it in output folder)

One you reference it the following code can be used to process the cube dynamically.

First connect to the Server by creating object of Server class and passing connection string to it.

 Server server = new Server();

 server.Connect("Data source=YourSSASServerName;Timeout=7200000;Integrated Security=SSPI");

I have not provided Username and Password in connection string as SSAS automatically gets authenticated by using windows identity of the calling user. Also I have increased timeout to 2 hrs. i.e. 7200000 milliseconds as processing big cube can take more time.

It also has EffectiveUserName property by which you can specilfy the user identity to be used while processing the cube but for that too, the calling user must have rights to SSAS server.

For other details regarding Connection String Properties (Analysis Services) I will recommend to visit here.

Once you connect to server then you need to get database class object as per your database name.

Database database = server.Databases.FindByName("YourCubeDBName");

NOTE: If your dimension data has been changed then you need to process database rather processing cube.

To process database following code can be used

database.Process(ProcessType.ProcessFull);

If you want process specific cube then you need to find it in Cube class object like below

Cube cube = database.Cubes.FindByName("YourCubeName");

Once you get cube object then to process it simply use following code.

cube.Process(ProcessType.ProcessFull);

NOTE: I have used ProcessFull option to process cube fully you can use different options available as per your need.

That’s it! Your cube has been processed and ready to browse.

Hope you have benefited from this code. I have also shared sample project of Process Cube for reference which you can download below.

Download Process Cube in C# Sample Project



If you enjoyed this post take 5 seconds to share it! Be Socialable. :-)

Share with WhatsApp

Posts To Read Next

How to Create New SSAS Cube from existing dynamically in C#

You can programmatically create a new cube from an existing cube in C# by changing its name and source database name. Read this post to know in detail.


Top 10 Visual Studio things which can boost developers coding speed

Visual Studio 2012 provides some coding features by which you can code faster if use them properly. This post will cover top 10 things among them to boost your development speed.


Visual Studio 2008 Shell and TFS integration

Visual Studio 2008 Shell and TFS integration is the problem for all newbies of BIDS and TFS. Here is the solution.


How to call click or any event only once in jQuery

Know how to execute an click event or any event only once for any element in jQuery. Perform action only once and even not required to unbind event.


Assembla - Free and private repository to manage your source code online with SVN subversion hosting

With Assembla you can share source code with others online. Free & Private source code repository with SVN Subversion, Git & Perforce Hosting.


Your opinion is valuable for us! Comments, suggetions are welcome.


Submit your Email Id to stay updated with us and get notified with our new posts. It's FREE!
We know this popup is disturbing you!
But We would greatly appreciate if you share us with your friends below!

It will not take more than 2 seconds but will motivate us greatly to write more,share more!

x