ComponentOne Olap for WinForms
OLAP Cube / Connecting to a Cube
In This Topic
    Connecting to a Cube
    In This Topic

    The ConnectCube method is used to connect to a cube in the database. This method accepts two parameters: the name of the cube and the connection string to the installed SSAS. The connection string must specify the Data Source (server name) and the Initial Catalog (database name). The version of the Provider must also be specified if more than one Microsoft OLE DB provider for OLAP is installed. For example, when the Provider is set to MSOLAP the latest version of OLE DB for OLAP installed on your system is used.

    The following code illustrates an example of connecting to a cube.

    Visual Basic (Change the Data Source and Initial Catalog in the ConnectionString before running the code)
    Copy Code
       'prepare to build view
        Dim connectionString As String = "Data Source=ServerAddress; Provider=msolap; Initial Catalog=DatabaseName"
        Dim cubeName As String = "Adventure Works"
        Try
        c1OlapPage1.OlapPanel.ConnectCube(Adventure Works, connectionString)
        ' show some data
        Dim olap = c1OlapPage1.OlapEngine
        olap.BeginUpdate()
        olap.ColumnFields.Add("Color")
        olap.RowFields.Add("Category")
        olap.ValueFields.Add("Order Count")
        olap.EndUpdate()
        Catch ex As Exception
        MessageBox.Show(ex.Message)
        End Try
    

    C# (Change the Data Source and Initial Catalog in the ConnectionString before running the code)
    Copy Code
        // prepare to build view           
       string connectionString = @"Data Source=ServerAddress; Provider=msolap; Initial Catalog=DatabaseName";
       string cubeName = "Adventure Works";
       try
        {
        c1OlapPage1.OlapPanel.ConnectCube(Adventure Works, connectionString);
        // show some data
       var olap = c1OlapPage1.OlapEngine;
       olap.BeginUpdate();
       olap.ColumnFields.Add("Color");
       olap.RowFields.Add("Category");
       olap.ValueFields.Add("Order Count");
       olap.EndUpdate();
        }
       catch (Exception ex)
        {
       MessageBox.Show(ex.Message);
        }  
    

    C1Olap also allows connection to local cube files (.cub). You can load a local cube file in the same way as connecting to a remote cube.

    The following code illustrates loading a local cube file LocalCube present in the Data folder.

    Visual Basic
    Copy Code
    Dim connectionString As String = "Data Source=" + System.AppDomain.CurrentDomain.BaseDirectory + "\Data\LocalCube.cub;Provider=msolap"
    Dim cubeName As String = "LocalCube"
    C1OlapPage1.OlapPanel.ConnectCube(cubeName, connectionString)
    

    C#
    Copy Code
    string connectionString = @"Data Source="+ System.AppDomain.CurrentDomain.BaseDirectory + @"\Data\LocalCube.cub;Provider=msolap";
    string cubeName = "LocalCube";
    c1OlapPage1.OlapPanel.ConnectCube(cubeName, connectionString);