// Create instance of Analysis Services object
AMO.Server aServer = new AMO.Server();
ArrayList aDimensionList = new ArrayList();
ArrayList aCubeList = new ArrayList();
try
{
//Get SSAS_DataMart connection string
string strConnection = "";
foreach (ConnectionManager aManager in this.Dts.Connections)
{
if (aManager.Name == "DataMart")
{
strConnection = aManager.ConnectionString;
}
}
//Throw error if not such connection manager
if (strConnection == "")
{
Exception ex = new Exception("No OLAP Connection manager: OLAP_DataMart found");
}
// Connect to DataMart instance of Analysis Services
aServer.Connect(strConnection);
string strCatalog = aServer.ConnectionInfo.Catalog;
//Get the Database name
AMO.Database myDataBase = aServer.Databases[strCatalog];
System.Diagnostics.Debug.WriteLine(" Database Id = " + myDataBase.ID);
Dts.Variables["_DatabaseName"].Value = myDataBase.ID;
//Get list of dimension and set to the DTS Variable
foreach (AMO.Dimension aDimension in myDataBase.Dimensions)
{
System.Diagnostics.Debug.WriteLine(" Dimension Id = " + aDimension.ID);
aDimensionList.Add(aDimension.ID);
}
Dts.Variables["_DimensionList"].Value = aDimensionList;
//Get list of Cube and set to the DTS Variable
foreach (AMO.Cube aCube in myDataBase.Cubes)
{
System.Diagnostics.Debug.WriteLine("Cube = " + aCube.ID);
aCubeList.Add(aCube.ID);
}
Dts.Variables["_CubeList"].Value = aCubeList;
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
Dts.TaskResult = (int)ScriptResults.Failure;
Dts.Variables["Pamlico_PackageExecutionResult"].Value = Dts.TaskResult;
throw (ex);
}
finally
{
// DisConnect to the local instance of Analysis Services
if (aServer != null)
{
if (aServer.Connected)
{
aServer.Disconnect();
}
}
}
Dts.TaskResult = (int)ScriptResults.Success;
Dts.Variables["PackageExecutionResult"].Value = Dts.TaskResult;