Cannot create cube using DSO or using ADOMD -
07-15-2005
, 10:26 AM
What am I doing wrong?
When I try to create a cube using DSO, I get an error saying, 'Cannot
update. Database or object is read-only.'. The code is:
dsoServer.Connect( GssCommonAPI.GetConfigKey("OLAPServerName") );
// Ensure that the database exists
if( dsoServer.MDStores.Find( databaseName ) == false )
errMsg = string.Format("Database {0} is not found.",
databaseName);
else
{
// get the database
dsoDatabase = (DSO.MDStore)dsoServer.MDStores.Item(databaseName) ;
DSO.Database localDSODatabase =
(DSO.Database)dsoServer.MDStores.Item(databaseName );
// Check for existing data sources, dimensions, and cubes.
if( dsoDatabase.DataSources.Count == 0 )
errMsg = string.Format("Database {0} has no data sources.",
databaseName);
else if( dsoDatabase.Dimensions.Count == 0 )
errMsg = string.Format("Database {0} has no dimensions",
databaseName);
else if( dsoDatabase.MDStores.Find(cubeName) )
errMsg = string.Format("cube {0} already exists in database {1}",
cubeName, databaseName);
else
{
bool IsReadWrite = dsoDatabase.IsReadWrite;
// add the new cube
localDSODatabase.Cubes.AddNew(cubeName,
DSO.SubClassTypes.sbclsRegular);
DSO.Cube newCube =
(DSO.Cube)dsoDatabase.MDStores.AddNew(cubeName,
DSO.SubClassTypes.sbclsRegular);
dsoCube = (DSO.MDStore)dsoDatabase.MDStores.AddNew(cubeName,
DSO.SubClassTypes.sbclsRegular);
dsoCube.DataSources.AddNew(
dsoDatabase.DataSources.Item(1).ToString(),
DSO.SubClassTypes.sbclsRegular );
dsoCube.EstimatedRows = 100000;
// Add Dimensions
dsoCube.Dimensions.AddNew("Products",
DSO.SubClassTypes.sbclsRegular);
// Add two measures
dsoCube.Measures.AddNew("Store Cost",
DSO.SubClassTypes.sbclsRegular);
dsoCube.Update();
result = true;
}
}
--------------------------------------------------------------
And when I try using ADOMD, I always get a token not valid error:
protected string createCubeString = @"CREATE CUBE SalesLocal
(
MEASURE [SalesCustomer].[Actual],
MEASURE [SalesCustomer].[Budget],
MEASURE [SalesCustomer].[No Of Customers],
DIMENSION [SalesCustomer].[Product],
DIMENSION [SalesCustomer].[Warehouse]
)
";
Connection con = new ADODB.ConnectionClass();
ADOMD.Catalog ct = new Catalog();
ADOMD.Cellset cellSet = new CellsetClass();
try
{
con.Open(constr,"sa","",0);
ct.ActiveConnection = con;
int totalcubes = 0;
totalcubes = ct.CubeDefs.Count;
//cellSet.ActiveConnection = con;
//cellSet.Source = createCubeString;
cellSet.Open(createCubeString, con);
body.Text = totalcubes.ToString();
}
catch(Exception e)
{
body.Text = e.Message;
}
finally
{
con.Close();
} |