Search code examples
ssasetlrhino-etl

SSAS with Rhino ETL?


Is it possible to query an SSAS database using MDX and use this as a datasource for Rhino ETL? I am talking about making an OLE DB connection to the SSAS instance here.

Thanks!


Solution

  • If you're using Rhino ETL within a .NET application, then yes. First, reference Microsoft.AnalysisServices.AdomdClient.dll. Then, implement Rhino ETL's AbstractOperation to extract the data. Here's an example:

    namespace Etl.Operations
    {
        public class ExtactFromAnalysisServices : AbstractOperation
        {
            private readonly AdomdConnection _connection;
            private readonly string _mdx;
    
            public ExtactFromAnalysisServices(string connectionString, string mdx)
            {
                _connection = new AdomdConnection(connectionString);
                _mdx = mdx;
    
                _connection.Open();
            }
    
            public override IEnumerable<Row> Execute(IEnumerable<Row> rows)
            {
                var command = _connection.CreateCommand();
    
                command.CommandText = _mdx;
    
                using (var reader = command.ExecuteReader())
                    while (reader.Read())
                        yield return Row.FromReader(reader);
            }
    
            public sealed override void Dispose()
            {
                _connection.Close();
                _connection.Dispose();
                base.Dispose();
            }
        }
    }
    

    Use it in a process like this:

    public class Process : EtlProcess
    {
        protected override void Initialize()
        {
            Register(new ExtactFromAnalysisServices("connection string", "mdx query"));
            Register(new SomeTransform());
            Register(new SomeLoad());
        }
    }