Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem creating new partition in cube

Status
Not open for further replies.

mdengler

Programmer
Mar 21, 2002
4
US
I am trying to write a C# backend program that will handle the database maintenance that I would otherwise have to do via Microsoft's Analysis Services front end GUI Wizards. Currently I am having a problem with recreating the SliceValue. The value is a time dimension and should equate to [Monthly Dates].[Year].[Quarter].[Month] and instead it is these same values, but instead of being seperated by periods it has some sort of non-displayable character (maybe a newline) that is placing each value on a new line. The error I receive when I attempt to process the partition is as follows:

An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in ProcessCubes.exe

Additional information: Processing error [Object does not exist] '[All]
[2003]
[Quarter 2]
[May]'

The code is below.

Code:
		public void ProcessCubeIncremental(string ServerName, string DatabaseName, string Frequency, string CubeName, string FactTableName, string ReportDate)
		{
			DSO.ServerClass dsoServer = new DSO.ServerClass();
			DSO.MDStore dsoDatabase;
			DSO.MDStore dsoCube;
			DSO.MDStore dsoPartitionNew;
			DSO.MDStore dsoPartitionOld;
			DSO.Dimension dsoDimension;
			DSO.Level dsoLevel;
			//DSO.Level dsoLevelAll;
			//DSO.Level dsoLevelYear;
			//DSO.Level dsoLevelQuarter;
			//DSO.Level dsoLevelMonth;
			DSO.Property dsoProperty;
			DateTime dt = Convert.ToDateTime(ReportDate);
			GregorianCalendar c = new GregorianCalendar(GregorianCalendarTypes.Localized);
			int YearOld = c.GetYear(c.AddMonths(dt,-1));
			int MonthOld = c.GetMonth(c.AddMonths(dt,-1));
			string YearOldStr = YearOld.ToString();
			string MonthOldStr;
			if (MonthOld < 10)
			{
				MonthOldStr = &quot;0&quot;+MonthOld.ToString();
			}
			else
			{
				MonthOldStr = MonthOld.ToString();
			}
			int YearNew = c.GetYear(dt);
			int MonthNew = c.GetMonth(dt);
			string YearNewStr = YearNew.ToString();
			string MonthNewStr;
			if (MonthNew < 10)
			{
				MonthNewStr = &quot;0&quot;+MonthNew.ToString();
			}
			else
			{
				MonthNewStr = MonthNew.ToString();
			}
			
			switch(MonthNew)       
			{         
				case 1:         
					MonthNewName = &quot;January&quot;;
					break;                  
				case 2:         
					MonthNewName = &quot;February&quot;;
					break;                  
				case 3:         
					MonthNewName = &quot;March&quot;;
					break;                  
				case 4:         
					MonthNewName = &quot;April&quot;;
					break;                  
				case 5:         
					MonthNewName = &quot;May&quot;;
					break;                  
				case 6:         
					MonthNewName = &quot;June&quot;;
					break;                  
				case 7:         
					MonthNewName = &quot;July&quot;;
					break;                  
				case 8:         
					MonthNewName = &quot;August&quot;;
					break;                  
				case 9:         
					MonthNewName = &quot;September&quot;;
					break;                  
				case 10:         
					MonthNewName = &quot;October&quot;;
					break;                  
				case 11:         
					MonthNewName = &quot;November&quot;;
					break;                  
				case 12:         
					MonthNewName = &quot;December&quot;;
					break;                  
			}

			string PartitionNameOld = &quot;p&quot;+YearOldStr+MonthOldStr;
			string PartitionNameNew = &quot;p&quot;+YearNewStr+MonthNewStr;
			string ReportDateStart = MonthNewStr+&quot;/1/&quot;+YearNewStr;
			string ReportDateRange;
			string ReportDateEnd = MonthNewStr+&quot;/&quot;+c.GetDaysInMonth(YearNew,MonthNew).ToString()+&quot;/&quot;+YearNewStr;
			if (Frequency == &quot;Daily&quot;)
			{
				ReportDateRange = &quot;between '&quot; + ReportDateStart + &quot;' and '&quot; + ReportDateEnd + &quot;'&quot;;
			}
			else
			{
				ReportDateRange = &quot;= '&quot; + ReportDateEnd + &quot;'&quot;;
			}
			

			// Connect to the local server
			dsoServer.Connect(ServerName);

			// Set up the MDStore objects:
			// database, cube, and partition.
			dsoDatabase = (DSO.MDStore) dsoServer.MDStores.Item(DatabaseName);
			dsoCube = (DSO.MDStore) dsoDatabase.MDStores.Item(CubeName);
			dsoPartitionOld = (DSO.MDStore) dsoCube.MDStores.Item(PartitionNameOld);
			// delete the partition if it already exists
			if (dsoCube.MDStores.Find(PartitionNameNew) == true)
			{
				dsoCube.MDStores.Remove(PartitionNameNew);
			}

			// Create a new partition.
			dsoPartitionNew = (DSO.MDStore) dsoCube.MDStores.AddNew(&quot;~temp&quot;, DSO.SubClassTypes.sbclsRegular);

			// Clone the properties from the desired partition to the new partition.
			dsoPartitionOld.Clone(dsoPartitionNew, DSO.CloneOptions.cloneMajorChildren);

			// Change the partition name from &quot;~temp&quot; to the name intended for the new partition.
			dsoPartitionNew.Name = PartitionNameNew;
			dsoPartitionNew.AggregationPrefix = PartitionNameNew+&quot;_&quot;;

			//dsoPartitionNew.SourceTable = &quot;\&quot;dbo\&quot;.\&quot;&quot;+FactTableName+&quot;\&quot;&quot;;
			dsoPartitionNew.SourceTable = &quot;\&quot;&quot;+FactTableName+&quot;\&quot;&quot;;

			// Estimate the rowcount from the reference partition.
			dsoPartitionNew.EstimatedRows = dsoPartitionOld.EstimatedRows;

			dsoPartitionNew.SourceTableFilter = dsoPartitionNew.SourceTable + &quot;.\&quot;ReportDate\&quot; &quot; + ReportDateRange;

			// Set the FromClause and JoinClause properties of the new partition.
			//dsoPartitionNew.FromClause = dsoPartitionOld.FromClause.Replace(dsoPartitionOld.SourceTable, dsoPartitionNew.SourceTable);
			//dsoPartitionNew.JoinClause = dsoPartitionOld.JoinClause.Replace(dsoPartitionOld.SourceTable, dsoPartitionNew.SourceTable);

			// Change the definition of the data Slice used by the new partition.
			// Change the SliceValue properties of the affected levels and dimensions to the correct values.
			switch(MonthNew)       
			{         
				case 1:         
				case 2:   
				case 3:   
					Quarter = 1;
					break;                  
				case 4:            
				case 5:            
				case 6:            
					Quarter = 2;
					break;           
				case 7:            
				case 8:            
				case 9:            
					Quarter = 3;
					break;           
				case 10:            
				case 11:            
				case 12:            
					Quarter = 4;
					break;           
			}

			// Change the definition of the data slice used by the new
			// partition, by changing the SliceValue properties of the 
			// affected levels and dimensions to the desired values.
			dsoDimension = (DSO.Dimension) dsoPartitionNew.Dimensions.Item(&quot;Monthly Dates&quot;);
			dsoDimension.CustomProperties.Clear();
			//dsoDimension.CustomProperties.Remove(&quot;SliceValue&quot;);
			//dsoDimension.CustomProperties.Add(&quot;[All].[&quot;+YearNewStr+&quot;].Quarter &quot;+Quarter.ToString()+&quot;].[&quot;+MonthNewStr+&quot;]&quot;,&quot;SliceValue&quot;,VBA.VbVarType.vbString);
			//dsoLevels = (DSO.Level) dsoDimension.Levels.Item(&quot;(All).Year.Quarter.Month&quot;);
			//dsoLevels.SliceValue = &quot;[All].[&quot;+YearNewStr+&quot;].[Quarter &quot;+Quarter.ToString()+&quot;].[&quot;+MonthNewName+&quot;]&quot;;
			//dsoProperty = (DSO.Property) dsoDimension.CustomProperties.Add(&quot;[All]&quot;,&quot;(All)&quot;,VBA.VbVarType.vbString);
			//dsoProperty = (DSO.Property) dsoDimension.CustomProperties.Add(&quot;[&quot;+YearNewStr+&quot;]&quot;,&quot;Year&quot;,VBA.VbVarType.vbString);
			//dsoProperty = (DSO.Property) dsoDimension.CustomProperties.Add(&quot;[Quarter &quot;+Quarter.ToString()+&quot;]&quot;,&quot;Quarter&quot;,VBA.VbVarType.vbString);
			//dsoProperty = (DSO.Property) dsoDimension.CustomProperties.Add(&quot;[&quot;+MonthNewName+&quot;]&quot;,&quot;Month&quot;,VBA.VbVarType.vbString);
			dsoLevel = (DSO.Level) dsoDimension.Levels.Item(&quot;(All)&quot;);
			dsoLevel.SliceValue = &quot;[All]&quot;;
			dsoLevel = (DSO.Level) dsoDimension.Levels.Item(&quot;Year&quot;);
			dsoLevel.SliceValue = &quot;[&quot;+YearNewStr+&quot;]&quot;;
			dsoLevel = (DSO.Level) dsoDimension.Levels.Item(&quot;Quarter&quot;);
			dsoLevel.SliceValue = &quot;[Quarter &quot;+Quarter.ToString()+&quot;]&quot;;
			dsoLevel = (DSO.Level) dsoDimension.Levels.Item(&quot;Month&quot;);
			dsoLevel.SliceValue = &quot;[&quot;+MonthNewName+&quot;]&quot;;
			//dsoLevelAll = (DSO.Level) dsoDimension.Levels.Item(&quot;(All)&quot;);
			//dsoLevelAll.SliceValue = &quot;[All]&quot;;
			//dsoLevelYear = (DSO.Level) dsoDimension.Levels.Item(&quot;Year&quot;);
			//dsoLevelYear.SliceValue = &quot;[&quot;+YearNewStr+&quot;]&quot;;
			//dsoLevelQuarter = (DSO.Level) dsoDimension.Levels.Item(&quot;Quarter&quot;);
			//dsoLevelQuarter.SliceValue = &quot;[Quarter &quot;+Quarter.ToString()+&quot;]&quot;;
			//dsoLevelMonth = (DSO.Level) dsoDimension.Levels.Item(&quot;Month&quot;);
			//dsoLevelMonth.SliceValue = &quot;[&quot;+MonthNewName+&quot;]&quot;;

			// Save the partition definition in the metadata repository.
			dsoPartitionNew.Update();

			// Process the temporary partition.
			//dsoCube.LockObject(DSO.OlapLockTypes.olapLockProcess, &quot;Processing object...&quot;);
			dsoPartitionNew.Process(DSO.ProcessTypes.processFull);

			//dsoCube.UnlockObject();

			// Close the allocated resources and exit the subroutine.
			dsoCube = null;
			dsoDatabase = null;
			dsoServer.CloseServer();
			dsoServer = null;
		}

Please help me, I'm a desparate man!
 
It has been a while since I have done this but I think the issue my be with your use of the [ when you define each level of the slice

current code:
dsoLevel = (DSO.Level) dsoDimension.Levels.Item(&quot;Year&quot;);
dsoLevel.SliceValue = &quot;[&quot;+YearNewStr+&quot;]&quot;;

new code:
dsoLevel = (DSO.Level) dsoDimension.Levels.Item(&quot;Year&quot;);
dsoLevel.SliceValue = YearNewStr ;

the new code is more like what it should be. It may be easier to start with a single partition and hard code the values to debug. I remember that setting slice values was probably the hardest DSO operation I've done. Unfortunately I don't have my old code to check.




&quot;Shoot Me! Shoot Me NOW!!!&quot;
- Daffy Duck
 
Thanks MDXer for the quick response. Unfortunately, your suggestion yielded the same result:

Processing error [Object does not exist] 'All
2003
Quarter 2
May' ; Time:7/29/2003 1:21:28 PM

Any other ideas?
 
I know this is going to sound basic and stupid but when you browse your time dimension the names are as they appear above.

All
2003
Quarter 2
May

no diffrences for Example All Years or All Time, not QTR or any diffrences like that?


&quot;Shoot Me! Shoot Me NOW!!!&quot;
- Daffy Duck
 
Hey MDXer... tell me if this bizarre logic rings any bells. Thanks to your last post, it got me experimenting a bit more and here is what I found. It looks as though when you define a slicevalue via the partition editor wizard the level names that are used is the dimension's &quot;Member Name Column&quot; and when you set a slicevalue via DSO (using C# anyway) one must use the &quot;Member Key Column&quot;. Really stupid logic, but when I do it this way, the partition is processing successfully. Go figure!

Anyway, thanks a million... I owe you one.
 
Doesn't ring any bells, but it also doesn't suprise me. DSO can be a bear at times, especially partition slices.

The technique I have found easiest to use is the concept of an empty master Partition. I create the cube and point it at an empty view. I then apply any slice info. In dso I then clone the master and replace all the necessary info Partition name, source vieew/table, slice, aggregations. I have found it much easier and faster to clone and update info then totally creating new ones.

&quot;Shoot Me! Shoot Me NOW!!!&quot;
- Daffy Duck
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top