- Posted On 25 June 2014
- In Programming
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).
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
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.
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
- Tags :
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.
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.
Speed up coding in Visual Studio with code snippets & samples at your fingertips
Know how you can speed up coding in Visual Studio with Bing Developer Assistant by having millions of code snippets and sample projects at fingertips.
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.