New to Telerik Reporting? Download free 30-day trial

Connecting the CubeDataSource Component to an OLAP Database

When you configure a CubeDataSource you set the ConnectionString property to a connection string that includes information required to connect to the database. Specifying an appropriate connection string requires at least a server name and database (catalog) name. For information on valid connection strings see the ConnectionString property topic for the AdomdConnection class.

The sample code below illustrates how to connect a CubeDataSource component to the Adventure Works DW 2008R2 sample database:

Telerik.Reporting.CubeDataSource cubeDataSource = new Telerik.Reporting.CubeDataSource();

cubeDataSource.ConnectionString = "Data Source=localhost;Initial Catalog=Adventure Works DW 2008R2";
cubeDataSource.SelectCommand = "select non empty { [Measures].[Sales Amount] } on columns, " +
                               "       non empty { [Product].[Category].[Category] } on rows " +
                               "from [Adventure Works]";
Dim cubeDataSource As Telerik.Reporting.CubeDataSource = New Telerik.Reporting.CubeDataSource()

cubeDataSource.ConnectionString = "Data Source=localhost;Initial Catalog=Adventure Works DW 2008R2"
cubeDataSource.SelectCommand = "select non empty { [Measures].[Sales Amount] } on columns, " & _
                               "       non empty { [Product].[Category].[Category] } on rows " & _
                               "from [Adventure Works]"

Instead of setting connection strings as property settings in the CubeDataSource object, you can store them centrally as part of your application's configuration settings using the connectionStrings configuration element. This enables you to manage connection strings independently of your reports, including encrypting them using Protected Configuration. The following example shows how to connect to the Adventure Works DW 2008R2 sample database using a connection string which stored in the connectionStrings configuration element named MyAdventureWorksDW:

<configuration>
    <connectionStrings>
        <add name="MyAdventureWorksDW"
        connectionString="Data Source=localhost;Initial Catalog=Adventure Works DW 2008R2"
        providerName="Microsoft.AnalysisServices.AdomdClient" />
    </connectionStrings>
</configuration>

When the connection string is stored in the configuration file you need to specify the name of the configuration element as a value for the ConnectionString property of the CubeDataSource component:

Telerik.Reporting.CubeDataSource cubeDataSource = new Telerik.Reporting.CubeDataSource();

cubeDataSource.ConnectionString = "MyAdventureWorksDW";
cubeDataSource.SelectCommand = "select non empty { [Measures].[Sales Amount] } on columns, " +
                               "       non empty { [Product].[Category].[Category] } on rows " +
                               "from [Adventure Works]";
Dim cubeDataSource As Telerik.Reporting.CubeDataSource = New Telerik.Reporting.CubeDataSource()

cubeDataSource.ConnectionString = "MyAdventureWorksDW"
cubeDataSource.SelectCommand = "select non empty { [Measures].[Sales Amount] } on columns, " & _
                               "       non empty { [Product].[Category].[Category] } on rows " & _
                               "from [Adventure Works]"
In this article